日期:2014-05-18 浏览次数:20573 次
create table testtb(col int)
insert into testtb
select 1 union all select 2 union all select 3 union all
select 4 union all select 7 union all select 8
declare @p varchar(20) set @p='3,4,7'
--这样是不行的
--select * from @t where col in (@p)
--这样是可以的
select * from testtb where charindex(','+ltrim(col)+',',','+@p+',')>0
/*
col
-----------
3
4
7
*/
--或者
exec('select * from testtb where col in ('+@p+')')
/*
col
-----------
3
4
7
*/