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)
 Query for this

Author  Topic 

karthickbabu
Posting Yak Master

151 Posts

Posted - 2009-05-14 : 02:02:46


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

====================================================
you realize you've made a mistake, take immediate steps to correct it.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-14 : 02:24:48
If you are using SQL Server 2005, you can also use this method

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



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

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-05-14 : 02:28:14
declare @temp table ( Id varchar(30), Val varchar(30))

insert into @temp
select 'A1', 'AA' union all
select 'A1', 'AB' union all
select 'A1', 'AC' union all
select 'A2', 'BA' union all
select 'A2', 'BB' union all
select 'A3' ,'CA'

select distinct id ,stuff( (select ''+val from @temp where id = t.id for xml path('')),1,0,'') as val
from @temp t
Go to Top of Page
   

- Advertisement -