--实现split功能 的函数 Create function [dbo].[f_split](@SourceSql varchar(max),@StrSeprate varchar(10)) returns @temp table(val varchar(1000)) as begin declare @i int set @SourceSql=rtrim(ltrim(@SourceSql)) set @i=charindex(@StrSeprate,@SourceSql) while @i>=1 begin insert @temp values(left(@SourceSql,@i-1)) set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i) set @i=charindex(@StrSeprate,@SourceSql) end insert @temp values(@SourceSql) return end --运行结果 select * from f_split ('a1,a2,a3,a4',',')