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 |
nextaxtion
Yak Posting Veteran
54 Posts |
Posted - 2015-02-01 : 06:58:35
|
i have a table i need to show data according to id. distinct id and all name should be comma separated against each id. Please suggest how to write effective query for this scenario.DECLARE @TBL TABLE (ID NUMERIC(10), NAME VARCHAR(10))INSERT INTO @TBL (ID,NAME)VALUES(1, 'A'), (1,'B') ,(1,'C') ,(2,'E') ,(2,'B') , (3,'F') , (3,'G')output : id name 1 a,b,c2 e,b3 f,gprithvi nath pandey |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2015-02-01 : 13:29:13
|
[url]http://www.dbsimplified.com/2011/06/groupconcat-in-microsoft-sql-server.html[/url] |
|
|
akibintel
Starting Member
7 Posts |
Posted - 2015-02-02 : 01:06:35
|
Hi heres ur actually querySELECT distinct id, ( SELECT NAme+',' FROM mytbl t2 WHERE t2.id = t1.ID FOR XML PATH('') ) ConcatenatedFROM mytbl t1Thanks & Regards |
|
|
|
|
|
|
|