22,209
社区成员
发帖
与我相关
我的任务
分享
-- 建测试表
create table #t(s varchar(100))
insert into #t(s)
select '1,2,3,4,5,6,7,8,9,10'
-- 测试1
declare @x varchar(10)
select @x='1'
if exists(select 1 from #t where charindex(','+@x+',',','+s+',',1)>0)
print '存在'
else
print '不存在'
--> 结果: 存在
-- 测试2
declare @x varchar(10)
select @x='11'
if exists(select 1 from #t where charindex(','+@x+',',','+s+',',1)>0)
print '存在'
else
print '不存在'
--> 结果: 不存在
-- 测试3
declare @x varchar(10)
select @x='5'
if exists(select 1 from #t where charindex(','+@x+',',','+s+',',1)>0)
print '存在'
else
print '不存在'
--> 结果: 存在