Sql 中in语句,怎么赋值

来源:百度知道 编辑:UC知道 时间:2024/06/21 18:16:30
这段代码:
index=Split(session("chooseindex"),",") '将session("chooseindex")字符串变成数组
sql="select * from index where name in "&index&" order by ID"
'sql="select * from index where name in "&session('chooseindex')&" order by ID"
rs.open sql,conn,1,1
用上下面的查询语句均出错。
sql中的in语句,我看了说明用法为:"字段" in ("中国","朝鲜",... )
而session("chooseindex")中为(中国,朝鲜,... )
怎样实现正确查询?
一楼的sql="select * from index where name in "& cond &" order by ID"
不行 执行该sql还是出现
Microsoft OLE DB Provider for ODBC Drivers (0x80040E21)
语句错误
附:如果只是在外面加个括号,何须那么麻烦呢,直接在session或sql里加就可以了把。
还是条件(where name in *)的错误,我把条件一换,马上就没问题了。继续求怎么写这个查询条件,要进行过测试的。

感谢下面两位网友回答,我自己找到正确答案了
TO 阳光上的桥:
最后的sql形式一定是下面形式才执行:
sql="select * from index where name in ('name1','name2',...)"
你的是
sq

应该像我下面这样写:

index=Split(session("chooseindex"),",")
cond="("& join(index,"','") &")"
sql="select * from index where name in ('"& cond &"') order by ID"
response.write sql

你看看这个SQL有什么不对吧。

使用
for i=0 to ubound(index)
sql="select * from index where name="&rowd(i)&" order by ID"
next
你已经分离出来了就不用使用in 了