having 在多条件查询中,帮帮忙

来源:百度知道 编辑:UC知道 时间:2024/07/04 10:34:25
Set rs=server.createobject("adodb.recordset")
A=Request.form("A")
B=Request.form("B")
C=Request.form("C")

sql="Select A,sum(B), C from table where 1=1"
if A<>"" then sql=sql &"and A like '%"&A&"%' group by A"
if B<>0 then sql=sql &"and having(B)>="&B&" group by A"
if C<>"" then sql=sql &"and C='"&C&"' group by A"

rs.open sql,conn,1,1

问题:文本条件查询可以查到,但是有having就查不到,
原问题的应该是:
if B<>0 then sql=sql &"and having sum(B)>="&B&" group by A"
我改成了:
if B<>0 then sql=sql &" and group by yw_hao having sum(B)>="&B&""
还是不行啊!
如果改成:
if B<>0 then sql=sql &" and B>= "&B&" group by A"
就可以列出表,但是,不是sum(B)>="&B&" 了,而是列出了组A中的满足于B>= &qu

你的上sql拼错了:
if B<>0 then sql=sql &" and group by yw_hao having sum(B)>="&B&""

去掉【and】
if B<>0 then sql=sql &" group by yw_hao having sum(B)>="&B&""

---
以上,希望对你有所帮助。

Set rs=server.createobject("adodb.recordset")
A=Request.form("A")
B=Request.form("B")
C=Request.form("C")

sql="Select A,sum(B), C from table where 1=1"
if A<>"" then sql=sql &"and A like '%"&A&"%' group by A"
if B<>0 then sql=sql &"and group by A having(B)>="&B&""
if C<>"" then sql=sql &"and C='"&C&"' group by A"

rs.open sql,conn,1,1

" and group by ..." 这里语法都不正确了 ,多了 and

rs.open sql,conn,1,1 句之前看一下sql句的结果先。再把这个结果放到分析器里去运行,你就知道出错在哪 里了。这是给你渔了哦

还有一个问题