Sql :
alter function [fn_splitSTR]( @s varchar(8000), -- 5,6,7 @split varchar(10) -- ',')return @re table(col varchar(100))asbegindeclare @splitlen intset @splitlen=len(@split+'a ')-2while charindex(@split,@s)>0begin insert @re values(left(@s,charindex(@split,@s)-1)) set @s=stuff(@s,1,charindex(@split,@s)+ @splitlen,' ')end insert @re values(@s)returnend
执行:
select*from dbo.fn_splitSTR('5,6,7',',')
结果: