Count the number of results in a seperated list

Viewed 29

I know I could probably just count the commas but I wanted to know if theres a built in way to count the results in a comma seperated list?

e.g

DECLARE @IDs NVARCHAR(100)
SET @IDS = '2,3,54,234,'

SELECT
  COUNT(value FROM STRING_SPLIT(@IDs)) AS [Count]
FROM
  Table
1 Answers

Try this:

DECLARE @IDs NVARCHAR(100)
SET @IDS = '2,3,54,234,'

SELECT
    COUNT(*)
FROM 
    STRING_SPLIT(@IDs, ',') 
Related