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 |
|
lols
Posting Yak Master
174 Posts |
Posted - 2008-06-26 : 06:32:35
|
| Hi,I have the following:State-----OACATXARTUINI want the result as States-------------------OA,CA,TX,AR,TU,INHow to do this? |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-06-26 : 06:45:03
|
quote: Originally posted by lols Hi,I have the following:State-----OACATXARTUINI want the result as States-------------------OA,CA,TX,AR,TU,INHow to do this?
Try thisdeclare @t table ( state varchar(50))insert into @tselect 'OA' union allselect 'CA' Union allselect 'TX' Union allselect 'AR' Union allselect 'TU' Union allselect 'IN'select distinct stuff( (select ','+state from @t for xml path('')),1,1,'') as states from @t |
 |
|
|
lols
Posting Yak Master
174 Posts |
Posted - 2008-06-26 : 06:51:48
|
| thanks..very helpful |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|
|