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)
 Group help

Author  Topic 

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-04-22 : 07:28:41
Hi,
I need to Group the data based on ID.

A table data like this.


A id
--- -----
CI 2
FL 2
HA 2
HA 4
CI 6
HA 6
CI 9
HA 9
CI 10
HA 11


output required :

A id
--- ---
CI,FL,HA 2
HA 4
CI,HA 6
CI,HA 9
CI 10
HA 11



Karthik
http://karthik4identity.blogspot.com/

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-22 : 07:35:30
see concatenate records without UDF


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-22 : 08:46:27
[code]SELECT t.id,
STUFF((SELECT ','+ A FROM Table WHERE id=t.id FOR XML PATH('')),1,1,'') AS A
FROM (SELECT DISTINCT id FROM Table)t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-04-22 : 09:20:57
quote:
Originally posted by visakh16

SELECT t.id,
STUFF((SELECT ','+ A FROM Table WHERE id=t.id FOR XML PATH('')),1,1,'') AS A
FROM (SELECT DISTINCT id FROM Table)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






Yes, this saved my day..!!
Thanks a lot.

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-22 : 09:40:10
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -