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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help! SQL quiz

Author  Topic 

bluefishclock
Starting Member

2 Posts

Posted - 2009-03-16 : 14:15:17
Question:

Input :
OrderNo Batch
1111 1001
1111 1002
1111 1003
2222 2001
2222 2002











Write a SQL query which produces the following output

OrderNo Batch
1111 1001, 1002, 1003
2222 2001, 2002

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-16 : 14:21:19
see this

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=121788

also please note that this is script library, place for posting working scripts. post this in transact sql forums in future
Go to Top of Page

bluefishclock
Starting Member

2 Posts

Posted - 2009-03-16 : 14:31:20
thank you, and will do
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2009-03-17 : 05:58:43
moved from script library

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.5 out!
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-17 : 06:39:47
if u using 2005 u can use
select orderno, stuff((select ','+batch from tablename where orderno = t.orderno for xml path('')),1,1,'')as batch from tablename t
Go to Top of Page
   

- Advertisement -