Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Mar 24, 1997

Splitting Data Within a Column

Question:
I am trying to write a report that will bring back five individual pieces of data that are stored within the same column in a table. How do I do that?

Answer:
If a column contains a code like "AC14DF78YZ," where each of the pairs of letters and numbers need to be extracted separately for a report, the function SUBSTRING() [called SUBSTR() in some databases] will allow you to grab the individual pairs:

SELECT SUBSTRING(ColumnA FROM 1 FOR 2) FROM Table;
The above statement will return only the first two characters from the column. You can repeat the SUBSTRING function as many times as necessary to retrieve the data you need.

Your syntax for the SUBSTRING function may vary, so check your documentation for the exact syntax.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date