I couldnt find a forum for sql so Im going to post here. If Im in the wrong forum then please move me.

I have a table with following data
Fields:
OID, Product, Condition, QTY
DATA:
1, Product A, NEW, 60
2, Product A, B, 60
3, Product A, C, 40
4, Product B, NEW, 30
5, Product B, C, 20

I want to write my procedure so that when I execute it, it will return a table as such.
Product Name, NEW, B, C
Product A, 60, 60, 40
Product B, 30, 0, 20

SELECT PRODUCT,(CASE WHEN CONDITION LIKE 'NEW' THEN QTY END) AS NEW, (CASE WHEN CONDITION LIKE 'B' THEN QTY END) AS B, (CASE WHEN CONDITION LIKE 'C' THEN QTY END) AS C
FROM TEST

I got to the point where it will show different quantities in corresponding column but I was unable to merge them into single row.
Thank you in advance

I figured it out by using sub-queries for each column.
Thanks guys... uhmmm sigh not even one reply...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.