Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi All,Please tell me From following query how to get no of elements?SELECT SUBSTRING((SELECT ',' + s.NameFROM HumanResources.Shift sORDER BY s.NameFOR XML PATH('')),2,200000) AS CSVGO TIA
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-02-08 : 11:27:26
You can count the number of comma's like this:
SELECT csv, LEN(CSV)-LEN(REPLACE(CSV,',',''))+1 FROM (--- YOUR CODE HERE)S
If there are any commas in the data itself, this won't work.