njtd njtd - 6 months ago 61
SQL Question

SQL How to transpose table from row to column

I want to write sql query transpose table from row to column as picture below
enter image description here

Thank you very much.

Answer
I am not using exact names of columns u can try this    

SELECT GOOD2,NAME,
           MAX(CASE WHEN [TYPE] = 'BF' THEN VALUE END) BQTY,
           MAX(CASE WHEN [TYPE] = 'RC' THEN VALUE END) BQTY,
           MAX(CASE WHEN [TYPE] = 'ISU' THEN VALUE END) BQTY,
           MAX(CASE WHEN [TYPE] = 'CF' THEN VALUE END) BQTY
      FROM TABLE1
     GROUP BY GOOD2,NAME