-- =============================================
-- Author: gengc
-- Create date: <2012-12-29> -- Description: <字符串转Table>
-- Description: <字符串转Table>
-- SELECT * from dbo.F_StringToTable('123,aaa',',')
-- =============================================
create function [dbo].[F_StringToTable] (@str nvarchar(max),@split varchar(10))
returns @t Table (col varchar(100))
as
begin
declare @i int
declare @s int
set @i=1
set @s=1
while(@i>0)
begin
set @i=charindex(@split,@str,@s)
if(@i>0)
begin
insert @t(col) values(substring(@str,@s,@i-@s))
end
else begin
insert @t(col) values(substring(@str,@s,len(@str)-@s+1))
end
set @s = @i + 1
end
return
end
转载于:https://www.cnblogs.com/chengeng/p/4371633.html