首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

在select中关于in的使用。解决方案

2012-03-13 
在select中关于in的使用。VB code%...........srt12,23,45,67sqlselect * from table where id in(

在select中关于in的使用。

VB code
<%...........srt="12,23,45,67"sql="select * from table where id in('"&str&"')" '这样好像不行?...........%>

id为int类型,选择str里的id的数据,使用上面的语句好像不能通过。

[解决办法]
SQL code
--模拟数据表create table tablename(id int)insert into tablenameselect 12 union allselect 13 union allselect 14 union allselect 15 union allselect 16 union allselect 45 union allselect 46 union allselect 47declare @str varchar(14)set @str='12,23,45,67'exec('select * from tablename where id in ('+@str+')')/*id-----------1245*/
[解决办法]
SQL code
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&")" 
...........
%>
就可以了,不要单引号

热点排行