0

I have a table

enter image description here

and I want to convert it into one row for each customer number something like this:

enter image description here

Can someone point me to the right place , example where I can do similar thing.

1
  • The key term you are looking for is 'pivot'. I'm short on time now, but I can provide a solution later today if nobody beats me to it. Commented Feb 26, 2014 at 17:20

1 Answer 1

1

You need to use PIVOT. Something like the following query should help.

SELECT CustomerNumber, 
    CASE WHEN [1] > 0 THEN 'Y' ELSE 'N' END [Sony],
    CASE WHEN [2] > 0 THEN 'Y' ELSE 'N' END [LG],
    CASE WHEN [3] > 0 THEN 'Y' ELSE 'N' END [Samsung]
FROM
(SELECT Product1, CustomerNumber
    FROM Table) AS SourceTable
PIVOT
(
    COUNT(Product1)
    FOR Product1 IN ([1], [2], [3])
) AS PivotTable;
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.