回 帖 发 新 帖 刷新版面

主题:sql语句的问题

还是上次的问题

sql="select * from product where "&a(1)&" like '%%"&b(1)&"%%' "&a(3)&" "&a(2)&" like '%%"&b(2)&"%%' "

这样写对不对啊?

a(1),a(2)返回的是提交页面的列表的值-检索项
b(1),b(2)返回的是提交页面的文本框的值-关键词
a(3)返回的是提交页面的列表的值-返回的是"and","or"


假如
<select name="1">
<option value="and">与</option>
<option value="or">或</option>
request.form("1")返回的是"and","or"还是 and ,or 啊?

回复列表 (共22个回复)

11 楼

<select name="1">
<option value="and">与</option>
<option value="or">或</option>

当你选择“与”的时候,输出and,选择或的时候,输出or
如果不行,将name="1"改成字母加数字的,如name="n1",这样再试试

12 楼

不行啊

13 楼

抱歉,就是上次你帮我的,按钮点一下生成一个查询条件(包括列[列表],关键词[文本框],与或[列表]),提交查询的,我用数组保存他们的值,用response.write可以输出他们的值,可是用sql语句连起来写的时候总是得不到想要的结果,也不出错.就是where "&a(1)&" like '%%"&b(1)&"%%'......

14 楼

去掉一个%

15 楼

去掉以后,错误
错误类型:
Microsoft JET Database Engine (0x80040E14)
语法错误 (操作符丢失) 在查询表达式 'like '%h%' like '%gg%'' 中。


不去就不提示错误

16 楼

检查一下最后怎么多了一个单引号

17 楼

sql="select * from product where "&a(1)&" like '%%"&b(1)&"%%' "&a(3)&" "&a(2)&" like '%%"&b(2)&"%%' "
 

response.write sql
response.end

再查看一下页面 把语句放到SQL中 调试

18 楼

sql="select * from product where "&a(1)&" like '%%"&b(1)&"%%' "&a(3)&" "&a(2)&" like '%%"&b(2)&"%%' "

不出错,但得不到正确的结果

19 楼

代码是(以2个条件为例)
dim a(11),q,r,b(10)
  for q=1 to 11        '最多有11个列表,其中a(3,5,7,9,11)的值为“与”,“或”
    a(i)=request.Form("select"&q)
     response.Write(a(i)+"<br>")
  next
   
   b(1)=request.Form("guanjianci1")
  for r=2 to 12        '最多有6个文本框
   b(r)=request.Form("guanjianci"&r)
   r=r+1
  next
  sql="select * from product where "&a(1)&" like '%%"&b(1)&"%%' "&a(3)&" "&a(2)&" like '%%"&b(2)&"%%' order by "&px&""
response.Write(sql)
response.end
  rs.open sql,conn,1,1

输出的结果是
proid
proname
and

select * from product where like '%%h%%' like '%%gg%%' order by id

我上面以2个条件为例

还有个问题就是如何根据上个页面提交的条件的个数来写sql

比如上个页面有4个提交条件,在sql where中就应该有4个"&a(1)&" like '%%"&b(1)&"%%',如何弄啊?

20 楼

sql="select * from product where "&a(1)&" like '%"&b(1)&"%' and "&a(2)&" like '%"&b(2)&"%'"

我来回复

您尚未登录,请登录后再回复。点此登录或注册