我要查出当aid=4时,Product_Attribute包含aid的数据

我要查出当aid=4时,Product_Attribute包含aid的数据

显示出第一条记录,但不显示第二条记录,数据库如下:

id name Product_Attribute
1 pp 4,5,7,9
2 oo 45,14,41

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

这样写查询不出匹配的数据

第1个回答  2007-08-28
你得先把Product_Attribute查出来放到变量里然后再用变量比较,得到id列表,然后再用sql语句查出来.
aid=Trim(Request.QueryString("aid"))
set rsp=server.createobject("adodb.recordset")
sqlp="select id,Product_Attribute from Product"
rsp.open sqlp,conn,1,1
idlist=""
while not rsp.eof
arr = split(rs(1),",")
for each p in arr()
if p=aid then idlist =idlist&","&rsp(0)
next
idlist =idlist&","&rsp(0)
rsp.movenext
wend
rsp.close
if len(idlist)=0 then
cond = "where 1=0"
else
idlist = right(len(idlist)-1)
cond = "where id in ("&idlist&") order by Product_id"
end if

set rsp=server.createobject("adodb.recordset")
sqlp="select * from Product "&cond
rsp.open sqlp,conn,1,1

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网