标题:用sql语句查询时,出现错误提示
取消只看楼主
kent73
Rank: 1
等 级:新手上路
帖 子:61
专家分:5
注 册:2009-3-4
结帖率:46.67%
已结贴  问题点数:20 回复次数:2 
用sql语句查询时,出现错误提示
用如下语句进行查询,出现了错误提示,请帮助看看哪里有问题。谢谢!

sql = "SELECT A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs, Sum(B.dh*A.sl) AS yyl FROM A INNER JOIN B ON (A.hth = B.hth) AND (A.pf = B.pf) GROUP BY A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs where A.hth='" & & "' ORDER BY A.pf ASC "


错误提示:
实时错误 ‘-2147217900 (80040e14)’:语法错误(操作符丢失)在查询表达式’b.cgfs where a.hth=’a123’’中。
搜索更多相关主题的帖子: sql 语句 提示 查询 
2010-10-29 19:23
kent73
Rank: 1
等 级:新手上路
帖 子:61
专家分:5
注 册:2009-3-4
得分:0 
不好意思,整段代码如下:
Dim i, sql
 Dim rs As New ADODB.Recordset, cn As New ADODB.Connection
 
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
 If = "" Then
  MsgBox "只有输入了合同号,才能进行查询!", vbOKOnly, "提示"
 Exit Sub
 End If
 If rs.State = adStateOpen Then rs.Close
          sql = "SELECT A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs, Sum(B.dh*A.sl) AS yyl FROM A INNER JOIN B ON (A.hth = B.hth) AND (A.pf = B.pf) GROUP BY A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs where A.hth='" & & "' ORDER BY A.pf ASC "
    cn.CursorLocation = adUseClient
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Jet OLEDB:Database Password=;Persist Security Info=False;"

        rs.Open sql, cn, 1, 1
        Set Me.DataGrid1.DataSource = Nothing
        Set Me.DataGrid1.DataSource = rs
2010-10-29 19:56
kent73
Rank: 1
等 级:新手上路
帖 子:61
专家分:5
注 册:2009-3-4
得分:0 
以下是引用Artless在2010-10-29 23:30:45的发言:

sql = "SELECT A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs, Sum(B.dh*A.sl) AS yyl FROM A INNER JOIN B ON (A.hth = B.hth) AND (A.pf = B.pf) where A.hth='" & & "' GROUP BY A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs  ORDER BY A.pf ASC"
这样试试。
问题解决了
谢谢
2010-10-30 20:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-324407-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.808797 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved