日期:2014-05-18 浏览次数:20570 次
declare @s varchar(10) set @s='1,5,8'
select * from 你的表名
where charindex(','+ltrim(a1)+',',','+@s+',')=0
------解决方案--------------------
go
if OBJECT_ID('#tb')is not null
drop table #tb
go
create table #tb(
a1 int,
a2 int,
a3 int
)
go
insert #tb
select 5,9,7 union all
select 1,5,4 union all
select 2,6,1
declare @str varchar(max)
set @str='1,5,8'
select COUNT(a) as times from(
select * from(
select a1 as a from #tb
union
select a2 from #tb
union
select a3 from #tb) a where CHARINDEX(ltrim(a),@str)>0)b
/*
times
2
*/
--查询出现的数字
declare @str varchar(max)
set @str='1,5,8'
select * from(
select a1 as a from #tb
union
select a2 from #tb
union
select a3 from #tb) a where CHARINDEX(ltrim(a),@str)>0
/*
a
1
5
*/