0

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


1
  • 1
    Please show the results that you want. Commented Jul 22, 2020 at 21:30

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.