954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Merging multiple rows into 1

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

bluehangook629
Posting Whiz in Training
204 posts since Dec 2009
Reputation Points: 11
Solved Threads: 14
 

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

bluehangook629
Posting Whiz in Training
204 posts since Dec 2009
Reputation Points: 11
Solved Threads: 14
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: