create function isin(@s varchar(100),@c varchar(100))
returns bit
as
begin
declare @a table(a int)
declare @t varchar(20)
while len(@s)>0
begin
set @t=substring(@s,1,charindex(',',@s)-1)
set @s=stuff(@s,1,charindex(',',@s),'')
insert into @a select cast(@t as int) --可以直接判断然后用break退出
end
declare @r bit
if exists(select 1 from @a where ','+@c+',' not like '%,'+cast(a as varchar(10))+',%' )
set @r=0
else
set @r=1
return(@r)
end godecare @ss_fbr varchar(100)
set @ss_fbr='12,15,18'
select * from yourtable where dbo.isin(fbr,@ss_fbr)=1
returns bit
as
begin
declare @a table(a int)
declare @t varchar(20)
while len(@s)>0
begin
set @t=substring(@s,1,charindex(',',@s)-1)
set @s=stuff(@s,1,charindex(',',@s),'')
insert into @a select cast(@t as int) --可以直接判断然后用break退出
end
declare @r bit
if exists(select 1 from @a where ','+@c+',' not like '%,'+cast(a as varchar(10))+',%' )
set @r=0
else
set @r=1
return(@r)
end godecare @ss_fbr varchar(100)
set @ss_fbr='12,15,18'
select * from yourtable where dbo.isin(fbr,@ss_fbr)=1
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货