处理传递过来的拼接的值,中间用逗号相隔
alter proc ljgl_cp_yzzx @usetag int ,@ids varchar(1000) as begin begin tran tr1 select * into #temp from fn_split(@ids,',') update cp_advice set usetag=@usetag where [objid] in (select * from #temp) if @@ERROR<>0 goto final commit tran tr1 select '执行成功' msg,1 code return final:rollback tran tr1 select '执行失败' msg,0 code End ---调用方法:select * from fn_split('a,b',',') ALTER FUNCTION [dbo].[fn_split] ( @inputstr varchar(8000), @seprator varchar(10) ) returns @temp table (a varchar(200)) as begin declare @i int set @inputstr = rtrim(ltrim(@inputstr)) set @i = charindex(@seprator, @inputstr) while @i >= 1 begin insert @temp values(left(@inputstr, @i - 1)) set @inputstr = substring(@inputstr, @i +1, len(@inputstr) - @i) set @i = charindex(@seprator, @inputstr) end if @inputstr <> '' insert @temp values(@inputstr) return end select @code,@Name,@Phone,@Visit_people,DATEADD(D,ts,GETDATE()) ,lx,zt,0 from hfjhzq where zqid in (select * from [dbo].[fn_split](@Visit_ids,',')) FUNCTION [dbo].[fn_split] ( @inputstr varchar(8000), @seprator varchar(10) ) returns @temp table (a varchar(200)) as begin declare @i int set @inputstr = rtrim(ltrim(@inputstr)) set @i = charindex(@seprator, @inputstr) while @i >= 1 begin insert @temp values(left(@inputstr, @i - 1)) set @inputstr = substring(@inputstr, @i +1, len(@inputstr) - @i) set @i = charindex(@seprator, @inputstr) end if @inputstr <> '' insert @temp values(@inputstr) return end