日期:2014-05-17 浏览次数:22638 次
<%
...........
srt="12,23,45,67"
sql="select * from table where id in('"&str&"')" '这样好像不行?
...........
%>
--模拟数据表
create table tablename(id int)
insert into tablename
select 12 union all
select 13 union all
select 14 union all
select 15 union all
select 16 union all
select 45 union all
select 46 union all
select 47
declare @str varchar(14)
set @str='12,23,45,67'
exec('select * from tablename where id in ('+@str+')')
/*
id
-----------
12
45
*/
------解决方案--------------------
declare @str varchar(14) set @str='12,23,45,67' select * from tablename where ltrim(id) in (@str)
------解决方案--------------------
改成
<%
...........
srt="12,23,45,67"
sql="select * from table where id in("&str&")"
...........
%>
就可以了,不要单引号