语法错误 (操作符丢失) 在查询表达式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了语法错误 (操作符丢失) 在查询表达式相关的知识,希望对你有一定的参考价值。

技术信息(用于支持人员)

错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] 语法错误 (操作符丢失) 在查询表达式 'id=' 中。
/5/system/user_add.asp, 第 408 行

代码如下
</table>
</form>
<%
else
nowbianhao=request("bianhao")
nowqq=request("qq")
nowemail=request("email")
nowid_zu=request("id_zu")
nowusername=request("username")
nowpassword=request("password")
nowgongzi=request("gongzi")
nowxinbie=request("xinbie")
nowtel=request("tel")
nowaddress=request("address")
nowsfz=request("sfz")
nowquanxian=""
if request("quanxian1")="1" then
nowquanxian=nowquanxian&"1"
else
nowquanxian=nowquanxian&"0"
end if
for x=2 to 96
if request("quanxian"&x)="1" then
nowquanxian=nowquanxian&",1"
else
nowquanxian=nowquanxian&",0"
end if
next

sql="select * from login where bianhao='"&nowbianhao&"'"
set rs=conn.execute(sql)
if rs.eof=false then
%>
<script language="javascript">
alert("您输入的编号已经存在,请重新输入!")
window.history.go(-1)
</script>
<%
response.end
end if

sql="select * from login where username='"&nowusername&"'"
set rs=conn.execute(sql)
if rs.eof=false then
%>
<script language="javascript">
alert("您输入的姓名已经存在,如果有同名员工,请加以区分!")
window.history.go(-1)
</script>
<%
response.end
end if

if nowpassword="" then
nowpassword=0
else
sql="update login set bianhao='"&nowbianhao&"',username='"&nowusername&"',gongzi="&nowgongzi&",quanxian='"&nowquanxian&"',xinbie='"&nowxinbie&"',tel='"&nowtel&"',address='"&nowaddress&"',sfz='"&nowsfz&"',qq='"&nowqq&"',email='"&nowemail&"',id_zu="&nowid_zu&" where id="&request("id")

---行408---conn.execute(sql)
end if

sql="update login set bianhao='"&nowbianhao&"',username='"&nowusername&"',password='"&md5(nowpassword)&"',gongzi="&nowgongzi&",quanxian='"&nowquanxian&"',xinbie='"&nowxinbie&"',tel='"&nowtel&"',address='"&nowaddress&"',sfz='"&nowsfz&"',qq='"&nowqq&"',email='"&nowemail&"',id_zu="&nowid_zu&" where id="&request("id")
conn.execute(sql)
%>
<script language="javascript">
按照关大哥改完以后,是这个样子

错误类型:
Microsoft VBScript 编译器错误 (0x800A0401)
语句未结束
/5/system/user_add.asp, line 411, column 327
sql="update login set bianhao='"&nowbianhao&"',username='"&nowusername&"',password='"&md5(nowpassword)&"',gongzi="&nowgongzi&",quanxian='"&nowquanxian&"',xinbie='"&nowxinbie&"',tel='"&nowtel&"',address='"&nowaddress&"',sfz='"&nowsfz&"',qq='"&nowqq&"',email='"&nowemail&"',id_zu="&nowid_zu&" where id="&cstr(cint(request("id")))conn.execute(sql)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^

where id="&request("id")
改成
where id="&cstr(cint(request("id")))
参考技术A 得先判断request("id")是否为空

查询表达式中的语法错误(缺少运算符)

【中文标题】查询表达式中的语法错误(缺少运算符)【英文标题】:Syntax error (missing operator) in query expression 【发布时间】:2013-03-13 15:29:44 【问题描述】:

我有以下 SQL 语句在 SQL Server 中运行良好,但在 Access 中却出现错误

'ERM_HAZARD.[HAZARDID] = ERM_XREF_HAZARD_CAT.[HAZARDID] 
INNER JOIN ERM_HAZARDSTATUS 
ON ERM_HAZARD.HAZARDSTATUSID = ERM_HAZARDSTATUS.HAZARDSTATUSI'

 SELECT erm_hazard.hazardid    AS PKTrans,
       erm_hazard.extref      AS No,
       erm_cat.name           AS CaseType,
       erm_hazard.created     AS CaseDate,
       erm_hazard.name        AS Title,
       erm_hazard.description AS DescriptionTrans,
       erm_organisation.name  AS ResponsibleUnit,
       erm_hazard.reviewdate  AS CaseDeadline,
       erm_hazardstatus.name  AS Status,
       erm_organisation.name  AS UnitInCharge,
       erm_personel.name      AS PersonInCharge
FROM   (erm_personel
        INNER JOIN (erm_organisation
                    INNER JOIN erm_hazard
                            ON erm_organisation.[organisationid] =
                               erm_hazard.[organisationid])
                ON erm_personel.[personelid] = erm_hazard.[personelid])
       INNER JOIN (erm_cat
                   INNER JOIN erm_xref_hazard_cat
                           ON erm_cat.[catid] = erm_xref_hazard_cat.[catid])
               ON erm_hazard.[hazardid] = erm_xref_hazard_cat.[hazardid]
       INNER JOIN erm_hazardstatus
               ON erm_hazard.hazardstatusid = erm_hazardstatus.hazardstatusid
WHERE  (( ( erm_xref_hazard_cat.periodid ) = (SELECT Max(
                                             erm_xref_hazard_cat.periodid)
                                              FROM   erm_xref_hazard_cat) ))
ORDER  BY erm_xref_hazard_cat.periodid DESC,
          erm_hazard.hazardid,
          erm_cat.name  

这是 Access SQL 大小问题吗? 有任何想法吗?

【问题讨论】:

请说明您遇到的错误。 您可以使用查询设计窗口拖放连接以确保您拥有正确的 MS Access 语法。 【参考方案1】:

MS Access 对查询中的括号非常特别。当您有多表连接时,每个连接必须有一对括号:

SELECT ERM_HAZARD.HAZARDID AS PKTrans, 
    ERM_HAZARD.EXTREF AS No, 
    ERM_CAT.NAME AS CaseType, 
    ERM_HAZARD.CREATED as CaseDate, 
    ERM_HAZARD.NAME AS Title, 
    ERM_HAZARD.DESCRIPTION AS DescriptionTrans,  
    ERM_ORGANISATION.NAME AS ResponsibleUnit, 
    ERM_HAZARD.REVIEWDATE AS CaseDeadline, 
    ERM_HAZARDSTATUS.NAME as Status, 
    ERM_ORGANISATION.NAME AS UnitInCharge, 
    ERM_PERSONEL.NAME AS PersonInCharge 
FROM ((((ERM_PERSONEL 
INNER JOIN ERM_HAZARD 
    ON ERM_PERSONEL.[PERSONELID] = ERM_HAZARD.[PERSONELID])
INNER JOIN ERM_ORGANISATION 
    ON ERM_ORGANISATION.[ORGANISATIONID] = ERM_HAZARD.[ORGANISATIONID])
INNER JOIN ERM_XREF_HAZARD_CAT 
    ON ERM_HAZARD.[HAZARDID] = ERM_XREF_HAZARD_CAT.[HAZARDID])
INNER JOIN ERM_CAT 
    ON ERM_CAT.[CATID] = ERM_XREF_HAZARD_CAT.[CATID])
INNER JOIN ERM_HAZARDSTATUS 
    ON ERM_HAZARD.HAZARDSTATUSID = ERM_HAZARDSTATUS.HAZARDSTATUSID
WHERE ERM_XREF_HAZARD_CAT.PERIODID= (SELECT MAX(ERM_XREF_HAZARD_CAT.PERIODID) 
                                     FROM ERM_XREF_HAZARD_CAT) 
ORDER BY ERM_XREF_HAZARD_CAT.PERIODID DESC,  ERM_HAZARD.HAZARDID, ERM_CAT.NAME

【讨论】:

【参考方案2】:

添加到这个。如果要创建传递查询,则需要在声明 SQL 之前识别连接字符串。

sub test()
Dim dbs As Database
Dim qdf As DAO.QueryDef
Dim rstSQL As DAO.Recordset
Dim strSQL As String

On Error GoTo errTrap

Set dbs = CurrentDb

Set qdf = dbs.CreateQueryDef("")

qdf.Connect = ConStringMailing
qdf.ReturnsRecords = True

qdf.SQL = "Select * FROM TABLE"
Set rstSQL = qdf.OpenRecordset

errTrap:
end sub

【讨论】:

【参考方案3】:

'ERM_HAZARD.[HAZARDID] = ERM_XREF_HAZARD_CAT.[HAZARDID] 内部连接 ​​ERM_HAZARDSTATUS ON ERM_HAZARD.HAZARDSTATUSID = ERM_HAZARDSTATUS.HAZARDSTATUSI'

HAZARDSTATUSID 末尾缺少 de "D"

【讨论】:

以上是关于语法错误 (操作符丢失) 在查询表达式的主要内容,如果未能解决你的问题,请参考以下文章

语法错误 (操作符丢失) 在查询表达式

ASP语法错误 (操作符丢失) 在查询表达式 'PaperId=' 中。

帮忙挑毛病 C# asp.net “语法错误 (操作符丢失) 在查询表达式''中”错误

MS Acess不支持多个left join(语法错误(操作符丢失)在查询表达式 xx中)

LEFT JOIN连接SQL语句在Access里面报语法错误(操作符丢失),哪位帮帮忙?

语法错误。在查询表达式中-Delphi