Sql convert data into one row from multiple columns
I have a table
and I want to convert it into one row for each customer number something like this:
Can someone point me to the right place , example where I can do similar thing.
One Solution collect form web for “Sql convert data into one row from multiple columns”
You need to use PIVOT. Something like the following query should help.
SELECT CustomerNumber, CASE WHEN  > 0 THEN 'Y' ELSE 'N' END [Sony], CASE WHEN  > 0 THEN 'Y' ELSE 'N' END [LG], CASE WHEN  > 0 THEN 'Y' ELSE 'N' END [Samsung] FROM (SELECT Product1, CustomerNumber FROM Table) AS SourceTable PIVOT ( COUNT(Product1) FOR Product1 IN (, , ) ) AS PivotTable;