Splitting Data Within a Column

Question:
I am trying to write a report that will bring back fiveindividual 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 toretrieve the data you need.

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

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: