请教:SQLSERVER中IN子查询能用变量么?
declare @id_sz varchar(200)
set @id_sz='70,73,76,05'
select * from aTable where id_sz in (@id_sz) //这样查询不到信息
//如果用拼SQL语句的方式则或以,但我不能用那种方式
[解决办法]
--这样,用动态SQL.
declare @id_sz varchar(200) set @id_sz='70,73,76,05' exec('select * from aTable where id_sz in ('+@id_sz+')')
[解决办法]
--或者这样。declare @id_sz varchar(200) set @id_sz='70,73,76,05' select * from aTable where charindex(','+id_sz+',',','+@id_sz+',')>0
[解决办法]
2楼也可,就是效率没有 1楼好.