Try this..
Drop function CutCsv
go
Create function CutCsv(@CSVString varchar(max))
returns table
as
return(
with Num1 (n) AS (SELECT 1 UNION ALL SELECT 1),
Num2 (n) AS (SELECT 1 FROM Num1 AS X, Num1 AS Y),
Num3 (n) AS (SELECT 1 FROM Num2 AS X, Num2 AS Y),
Num4 (n) AS (SELECT 1 FROM Num3 AS X, Num3 AS Y),
Nums (n) AS (SELECT ROW_NUMBER() OVER(ORDER BY n) FROM Num4),
SpacesPos(sIndex)
as
(
Select n+1
from nums
where n spacesPos.SIndex)-1
from spacesPos
)
Select Item = ltrim(rtrim(substring(@CSVString,StartPos,(EndPos-StartPos))))
from cteSpaceDelta
where EndPos is not null
)
go
Select * from dbo.CutCsv('10,2,2,2,4,4,5')