处理SQL函数IN问题


create table #TMP(cs varchar(30))

declare @a nvarchar(50)='今日处理1,问题2'
declare @len1 int
declare @len2 int
declare @sql nvarchar(500)=''
set @len1=1
set @len2=CHARINDEX(',',@a)
SET @a=@a+','
while @len2<=LEN(@a) AND @len2<>0
begin
set @sql=SUBSTRING(@a,@len1,@len2-@len1)
insert into #TMP values(@sql)
set @len1=1+@len2
set @len2=CHARINDEX(',',@a,@len2+1)
end

select * from basDeviceTag where TagName in (select cs from #TMP)
drop table #TMP

原文地址:https://www.cnblogs.com/tippchlj/p/7065690.html