下面是创建了以“,”分割字符串的函数:
create function f_splitstr(@SourceSql varchar(8000),@StrSeprate varchar(100)) returns @temp table(F1 varchar(100)) as begin declare @ch as varchar(100) set @[email protected][email protected] while(@SourceSql<>‘‘) begin set @ch=left(@SourceSql,charindex(‘,‘,@SourceSql,1)-1) insert @temp values(@ch) set @SourceSql=stuff(@SourceSql,1,charindex(‘,‘,@SourceSql,1),‘‘) end return end ----调用 select * from dbo.f_splitstr(‘1,2,3,4‘,‘,‘)
时间: 2024-11-11 08:02:53