I am trying to use "for Xml Path" T-SQL to generate a comma-separated list of values ββfrom a column. This seems to work fine, but the problem is that I would like to get the number of items in a comma-separated list. The following is sample code that I use to create a comma separated list:
Create Table
Insert Into
Insert Into
Insert Into
Select ',' + [col] From
This gives results 1,2,3 as expected, but there is no way to get the score that there are 3 elements. Any attempt to add an account will simply add it to xml. I combined this code with cte to get the score:
With CTE As (
Select
[col]
From
)
Select
(Select ',' + [col] From
Count(*) As [Count]
From
CTE
/ CTE? , from , . , , , .