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)
 Transform record fields into single string

Author  Topic 

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2010-01-12 : 15:24:36
This...

select typedesc from desctypes where typegroup = 'HA'

Returns three records...

Level One
Level Two
Level Three

I want to return one record that looks like this...

Level One,Level Two,Level Three

I know this is common and basic but I google in vain.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-12 : 15:35:32
Why do you need to show it this way, If you have to show it in a front end, do your formatting there.
Try this though..
select stuff((select ',' + typedesc from desctypes where typegroup = 'HA' for xml path('')),1,1,'')
Go to Top of Page

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-01-12 : 15:56:47
Think you are missing a 'from' in there vijay.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-12 : 16:00:33
I sure did...edited it now
Go to Top of Page
   

- Advertisement -