Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
deadfish
Starting Member
38 Posts |
Posted - 2004-02-12 : 03:01:55
|
| Hi,Suppose I have a table table like this:order_no item_no -----------------ord1 item1ord1 item2ord1 item3ord2 item4ord2 item5I need to have a result like this:order_no item_no ------------------------------ord1 item1,item2,item3ord2 item4,item5 I have to merge similar rows into 1 row. Can I achieve this without using a cursor??Thanks for any help here! |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
|
|
PieterK
Starting Member
2 Posts |
Posted - 2004-03-05 : 05:58:45
|
quote: Originally posted by deadfish Hi,Suppose I have a table table like this:order_no item_no -----------------ord1 item1ord1 item2ord1 item3ord2 item4ord2 item5I need to have a result like this:order_no item_no ------------------------------ord1 item1,item2,item3ord2 item4,item5 I have to merge similar rows into 1 row. Can I achieve this without using a cursor??Thanks for any help here!
|
 |
|
|
PieterK
Starting Member
2 Posts |
Posted - 2004-03-05 : 06:06:50
|
quote: Originally posted by deadfish Hi,Suppose I have a table table like this:order_no item_no -----------------ord1 item1ord1 item2ord1 item3ord2 item4ord2 item5I need to have a result like this:order_no item_no ------------------------------ord1 item1,item2,item3ord2 item4,item5 I have to merge similar rows into 1 row. Can I achieve this without using a cursor??Thanks for any help here!
Hi, Sorry for the first reply that was empty!I Tested on SQL 2000There should be a Case scenario for each ItemSELECT order_no, (SELECT ANYNAME = CASE item_no WHEN 'item_1' THEN item_no ELSE 'NOTHING' END) AS ITEM_1,(SELECT ANYNAME = CASE item_no WHEN 'item_2' THEN item_no ELSE 'NOTHING' END) AS ITEM_2FROM YOUR_TABLENAME |
 |
|
|
|
|
|
|
|