I have a field that consists of different strings of letters in each row:
BAAAAZZAFBF
AAAAAZZAFBA
FAZZZAA
I would like to output these rows into columns based on each character (one column would be B, the next would be A, etc.).
I have this query right now but only transposes rows to columns - does not separate them.
SELECT Primary Key,
MAX(CASE WHEN DNB_MATCH_GRADE = 'B__________' THEN 1 END) B_Name,
MAX(CASE WHEN DNB_MATCH_GRADE = 'A__________' THEN 2 END) A_Name,
MAX(CASE WHEN DNB_MATCH_GRADE = 'F_______' THEN 3 END) F_name
FROM TABLE
GROUP BY Primary key
Output table would look like this with each section corresponding to a field in table:
Primary Key | A | B | D | Z | F
Is this what you want?
SELECT Primary Key,
MAX(CASE WHEN DNB_MATCH_GRADE = 'B__________' THEN DNB_MATCH_GRADE END) as B_Name,
MAX(CASE WHEN DNB_MATCH_GRADE = 'A__________' THEN DNB_MATCH_GRADE END) as A_Name,
MAX(CASE WHEN DNB_MATCH_GRADE = 'F_______' THEN DNB_MATCH_GRADE END) as F_name
FROM TABLE
GROUP BY Primary key