I have following function which accepts the CSV & delimeter & splits it
ALTER FUNCTION [dbo].[FN_Split] (@String varchar(max), @Delimiter char(1))
I think to clarify the comment from astander
try your code like this :
while @i<=@max
begin
if @i=0
begin
set @sql='insert into Person select items from dbo.FN_Split(@p_SourceText,
@p_Delimeter) where orderId = 00'
end
else
begin
if @i=(@max-1)
begin
set @sql=@sql+'UNION select items from dbo.FN_Split(@p_SourceText,
@p_Delimeter) where orderId ='+@i
end
else
begin
set @sql=@sql+'UNION select items from dbo.FN_Split(@p_SourceText,
@p_Delimeter) where orderId ='+@i UNION'
end
end
set @i=@i+1
end
END