CREATE FUNCTION [dbo].[F_split] ( @SourceSql VARCHAR(8000), @StrSeprate VARCHAR(10) ) RETURNS @table TABLE(ident INT IDENTITY(1, 1), f VARCHAR(500)) --实现split功能 的函数 AS BEGIN DECLARE @i INT SET @SourceSql = RTRIM(LTRIM(@SourceSql)) SET @i = CHARINDEX(@StrSeprate, @SourceSql) WHILE @i >= 1 BEGIN INSERT INTO @table ( f ) VALUES ( LEFT(@SourceSql, @i -1) ) SET @SourceSql = SUBSTRING(@SourceSql, @i + 1, LEN(@SourceSql) -@i) SET @i = CHARINDEX(@StrSeprate, @SourceSql) END IF @SourceSql <> '' INSERT INTO @table ( f ) VALUES ( @SourceSql ) RETURN END