SQL Where 字符串拼接

declare @s varchar(100)
set @s='1,2,3'

--法一:
select * from tb where charindex(','+ltrim(id)+',',','+@s+',')>0
--法二:
exec('select * from tb where id in ('+@s+')')

 

posted @ 2017-10-08 22:09  布洛克菲勒  阅读(2330)  评论(0编辑  收藏  举报