Declare @field varchar(50), @loc int
Set @field = '4;4;3;65;43;813;345'
Set @loc = 3
CREATE TABLE #temp (PkID Int Identity, Id INT NOT NULL)
declare @param VARCHAR(8000)
Set @param = REPLACE(@field, ';', ' UNION SELECT ')
Select @param
INSERT #temp EXEC ('SELECT ' + @param)
SELECT * FROM #temp Where pkid = @loc
Select Sum(ID) from #temp where pkid <=@loc
Drop table #Temp
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.