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 |
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2013-01-25 : 08:52:37
|
Hi All,I have a table T1 with column Namd and HobbiesName-HobbiesMichael-ShoppingMichael-MovieJames-ShoppingJames-MovieJames-DrawingNow I have to create on column Hobbies1 and paste hobbies value like belowName-Hobbies-Hobbies1Michael-Shopping-Shopping,MovieMichael-Movie-Shopping,MovieJames-Shopping-Shopping,Movie,DrawingJames-Movie-Shopping,Movie,DrawingJames-Drawing-Shopping,Movie,DrawingPlease suggest |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-01-25 : 09:02:56
|
[code]DECLARE @t tABLE (Name varchar(10), Hobbies varchar(15))insert into @tSELECT 'Michael','Shopping' union allSELECT 'Michael','Movie' union allSELECT 'James','Shopping' union allSELECT 'James','Movie' union allSELECT 'James', 'Drawing'SELECT name, Hobbies , STUFF(( SELECT ','+Hobbies FROM @t t2 WHERE t1.name= t2.Name FOR XML PATH('')), 1,1, '') AS Hobbies1FROM @t t1[/code]--Chandu |
|
|
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2013-01-30 : 05:52:46
|
Thanks Chandu,I have given just an example I am having around more than 10000 rows for this. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-30 : 05:54:42
|
quote: Originally posted by sanjay5219 Thanks Chandu,I have given just an example I am having around more than 10000 rows for this.
Thats not an issueyou can still apply the same method------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|