Give this a shot. It'll split and load your CSV values into a table variable.
declare @string nvarchar(500)
declare @pos int
declare @piece nvarchar(500)
declare @strings table(string nvarchar(512))
SELECT @string = 'ABC,DEF,GHIJK,LMNOPQRS,T,UV,WXY,Z'
if right(rtrim(@string),1) <> ','
SELECT @string = @string + ','
SELECT @pos = patindex('%,%' , @string)
while @pos <> 0
begin
SELECT @piece = left(@string, (@pos-1))
--you now have your string in @piece
insert into @strings(string) values ( cast(@piece as nvarchar(512)))
SELECT @string = stuff(@string, 1, @pos, '')
SELECT @pos = patindex('%,%' , @string)
end
SELECT * FROM @Strings
Found and modified from Raymond at CodeBetter.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…