Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,

ID | Value
—- ——–----
1000 1
1000 2
1000 3
1001 4
1001 5
1001 6
1001 7

I need the output

1000 ID: 1,2,3
1001 ID: 4,5,6,7


What will be the sql server query to achieve.
Posted

COALESCE should probably be the answer your question.

Do go to this link to learn how to use COALESCE :
http://www.sqlprof.com/blogs/sqldev/archive/2008/03/31/how-to-list-multiple-rows-of-data-on-same-line.aspx[^]

*Mark as answer if this solves.
 
Share this answer
 
check with this
SQL
select * from <tablename> where ID ="1000" 
select * from <tablename> where ID ="1001" 

and reply me what is the status and mark as answer if its correct
 
Share this answer
 
v2
SQL
select distinct id,'ID: '+stuff((
select ', '+ cast(value as varchar(100)) from tmp_tnl   where id= a.id FOR XML PATH('')),1,1,'')
from tmp_tnl a
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900