SQLServer分隔字符串(函数)/*
  --该函数把传递过来的字符串转换成IN 后⾯的列表,可以处理以分号,逗号以及空格分隔的字符串*/
CREATE FUNCTION [f_ttInStr]
  (@SourceStr varchar(2000))--源字符串
RETURNS  @table table(list  varchar(50) )
AS
BEGIN
  select @sourcestr =  replace(@sourcestr,';',',')
  select @sourcestr = replace(@sourcestr,' ',',')
  if charindex(',',@sourcestr)>0
begin
    declare @i int
    declare @n int
    set @i=1
    while charindex(',',@sourcestr,@i)>0
    begin
      set @n=charindex(',',@sourcestr,@i)
      insert into @table values(substring(@sourcestr,@i, @n-@i) )
      set @i=@n+1
sql server拼接字符串函数    end
    insert into @table values(substring(@sourcestr,@i,len(@sourcestr)-@i+1))
  end
  else insert into @table values(@sourcestr)
  delete from @table where isnull(list,'') = ''
  return
END

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。