日期:2014-05-18  浏览次数:20449 次

求助:select in 问题
我现在有一个字符串@tem=‘11,12,13’
我现在要用select * from table where columnName in(@tem)操作,注意column是int类型的这改怎么处理?

------解决方案--------------------
exec('select * from table where columnName in(' + cast(@tem as varchar) + ')')
------解决方案--------------------
SQL code
exec('select * from table where columnName in('+@tem+')')

------解决方案--------------------
探讨
exec('select * from table where columnName in(' + cast(@tem as varchar) + ')')

------解决方案--------------------
SQL code
exec('select * from table where columnName in('+@tem+')')

------解决方案--------------------
SQL code
declare @tem as varchar(20)
set @tem = '11,12,13' 

print('select * from table where columnName in (' + cast(@tem as varchar) + ')')
/*
select * from table where columnName in (11,12,13)
*/

exec('select * from table where columnName in (' + cast(@tem as varchar) + ')')