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 |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2012-07-19 : 09:42:09
|
Hi,In sql, how can I separate values in a field i.e. field1 by comma?i.e.:field1, field2"hello" "james""myname" "get there""where" "moon"I would like to retrieve:hello, myname, whereHow is this done please without using a cursor?Thanks |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-19 : 09:48:10
|
seehttp://www.nigelrivett.net/SQLTsql/CSVStringSQL.htmlselect csvstr = stuff ( ( select ',' + field1 from tbl for xml path('') ) ,1,1,'')==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-19 : 09:52:28
|
SELECT SUBSTRING(( SELECT ', ' + columnNameFROM YourTAbleFORXML PATH('')), 2, 8000) AS CSV--------------------------http://connectsql.blogspot.com/ |
 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2012-07-19 : 10:17:55
|
Thanks |
 |
|
|
|
|