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

时间:2017-08-21 02:03:35

标签: sql .net vb.net visual-studio

Dim sql As String = "SELECT DISTINCT LED.IDX As IDX, CORPCODE, UNITTYPECODE, UPPERFORMATIONCODE, FORMATIONCODE, LED.UNITCODE As UNITCODE,LED.STORECODE As STORECODE, LED.SECTIONNO As SECTIONNO, LED.PARTNO As PARTNO, "
            sql &= " LED.BATCHNO As BATCHNO, UNITITEMCATEGORYCODE, LEDGERDATE, ENTITLEMENT, HOLDING, SURPLUS, SHORTAGE, COSTHOLDING, COSTENTITLEMENT, INITIALSTOCK, EMPLOYQTY, FIGHTQTY, ITEMAGE1, ITEMAGE2, ITEMAGE3,"
            sql &= " ITEMAGE4, LED.BAH_BEREK, LED.JENIS_BEREK, JPTD_NO, LASTUPDATE, LED.ITEMTYPECODE As ITEMTYPECODE, LED.TOOLTYPECODE As TOOLTYPECODE, LED.PAKAIBHGCODE, LED.PAKAICODE, ITEMNIDX, LED.CREATEID As CREATEID, "
            sql &= " LED.UPDATEID As UPDATEID, LED.CREATEDATE As CREATEDATE, LED.UPDATEDATE As UPDATEDATE, "
            sql &= " USERID, RANKCODE, SERVICENO, USERNAME, DESIGNATIONCODE, PASSWORD, "
            sql &= " 'OPER' AS GROUPCODE,5 AS ACESSID, 0 AS STATUS "
            sql &= " FROM (LEDGER AS LED) "
            sql &= " LEFT JOIN NUSER   On NUSER.USERID = LED.UPDATEID   WHERE (1=1)   "
            If condation <> "" Then
                sql += condation
            End If
            sql &= " UNION SELECT DISTINCT LED.IDX As IDX, CORPCODE, UNITTYPECODE, UPPERFORMATIONCODE, FORMATIONCODE, LED.UNITCODE As UNITCODE, LED.STORECODE As STORECODE, LED.SECTIONNO As SECTIONNO, LED.PARTNO As PARTNO, "
            sql &= " LED.BATCHNO As BATCHNO, UNITITEMCATEGORYCODE, LEDGERDATE, ENTITLEMENT, HOLDING, SURPLUS, SHORTAGE, COSTHOLDING, COSTENTITLEMENT, INITIALSTOCK, EMPLOYQTY, FIGHTQTY, ITEMAGE1, ITEMAGE2, ITEMAGE3,"
            sql &= " ITEMAGE4, LED.BAH_BEREK, LED.JENIS_BEREK, JPTD_NO, LASTUPDATE, LED.ITEMTYPECODE As ITEMTYPECODE, LED.TOOLTYPECODE As TOOLTYPECODE, LED.PAKAIBHGCODE, LED.PAKAICODE, ITEMNIDX, LED.CREATEID As CREATEID, "
            sql &= " LED.UPDATEID As UPDATEID, LED.CREATEDATE As CREATEDATE, LED.UPDATEDATE As UPDATEDATE,"
            sql &= " ('' AS USERID), ('' AS RANKCODE),('' AS SERVICENO),('' AS USERNAME),('' AS DESIGNATIONCODE), ('' AS PASSWORD), 'OPER',5 , STATUS "
            sql &= " FROM LEDGER_HISTORY LED WHERE (1=1) "

错误是查询表达式中的语法错误(缺少运算符)&#39;(&#39;&#39; AS USERID)&#39;。 任何人都可以帮我解决这个问题

1 个答案:

答案 0 :(得分:1)

错误是正确的。问题是括号。

此语法不适用于SQL:

SELECT ('' AS USERID)

但是,这是:

SELECT ('') AS USERID

或者只是:

SELECT '' AS USERID

FROM (LEDGER AS LED)存在同样的问题。