请高手过来帮忙解决个问题,where a in (b)

uran53 2007-08-28 09:35:31
aid=Trim(Request.QueryString("aid"))
set rsp=server.createobject("adodb.recordset")
sqlp="select * from Product where '"&aid&"' in (Product_Attribute) order by Product_id"
rsp.open sqlp,conn,1,1

注: aid=4 Product_Attribute字段类型为 varchar 值 4,5

查不出匹配的数据

将where '"&aid&"' in (Product_Attribute) 改成 where '"&aid&"' in (4,5)就可以
...全文
142 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
什么都不能 2007-08-28
  • 打赏
  • 举报
回复
sqlp="select * from Product where Product_Attribute like '%,"&aid&",%' or Product_Attribute like '"&aid&",%' or Product_Attribute like '%,"&aid&"'order by Product_id"
GoodyeahApple 2007-08-28
  • 打赏
  • 举报
回复
这样可不好办,你可以先用select * from Product取出所有记录 将Product_Attribute值转化为数组,然后用循环将数组值和aid 比较,如果有符合条件的就记下该条记录的id,然后再做查询select * from Product where id in(...) order by ...
uran53 2007-08-28
  • 打赏
  • 举报
回复
请高手过来帮忙解决一下啊,搞定了就送分,
uran53 2007-08-28
  • 打赏
  • 举报
回复
id name Product_Attribute
1 pp 4,5,7,9
2 oo 45,14,41

aid=4
我要显示出第一条记录,但不显示第二条记录
什么都不能 2007-08-28
  • 打赏
  • 举报
回复
where product_attribute in ("&aid&")
uran53 2007-08-28
  • 打赏
  • 举报
回复
是 Product_Attribute 包含 aid, 不是aid 包含 Product_Attribute

用like是不行的,因为 当aid=4 Product_Attribute=45 时 用in是没有匹配数据的,用like就有
uran53 2007-08-28
  • 打赏
  • 举报
回复
aid=任何数字
Product_Attribute=数字组成的任何数组(例:2,4,7,68,78.....)
GoodyeahApple 2007-08-28
  • 打赏
  • 举报
回复
sqlp="select * from Product where Product_Attribute like '%"&aid&"%'order by Product_id"
littlelam 2007-08-28
  • 打赏
  • 举报
回复
sqlp="select * from Product where Product_Attribute in ('"&aid&"') order by Product_id"
uran53 2007-08-28
  • 打赏
  • 举报
回复
是要查出 字段Product_Attribute 包含 aid 的数据
littlelam 2007-08-28
  • 打赏
  • 举报
回复
sqlp="select * from Product where Product_Attribute='"&aid&"'order by Product_id"
GoodyeahApple 2007-08-28
  • 打赏
  • 举报
回复
搞不懂你什么目的,是不是要查找 Product_Attribute字段值为 4的记录呀
uran53 2007-08-28
  • 打赏
  • 举报
回复
虽然没有搞清楚要怎么才能用in更方便的解决 ,但楼上的方法也是可以的

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧