Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error (missing operator) in query expression 1

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Hello,

I had this query works for MS SQL, but getting error running it for Access DB.
Code:
"SELECT pgRMAprods.prodSerialNo, " _
& "	SUM(CASE WHEN pgProducts.prodType='DVR' THEN pgRMAprods.itemQty END) AS countDVR, " _
& "	pgProducts.prodDesc " _
& "FROM pgRMAprods " _
& "INNER JOIN pgProducts " _
& "	ON pgRMAprods.idProduct = pgProducts.idProduct " _
& "WHERE pgRMAprods.idRMA = " & validSQL(rmaID,"I") & " " _
& "GROUP BY pgRMAprods.prodSerialNo, pgProducts.prodDesc " _
& "ORDER BY pgProducts.prodType DESC"

The error output is:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'SUM(CASE WHEN pgProducts.prodType='DVR' THEN pgRMAprods.itemQty END)'.


I guessed it can be query different between MS SQL and Access but don't know what is, please help.
 
In Access you need to use IIF function for conditional logic, e.g.
SUM(IIF(pgProducts.ProdType = 'DVR', pgRMAprods.ItemQty,0)) as CountDVR.

I hope this is the only one change required, although Access also likes to have lots of () for the JOIN conditions.

PluralSight Learning Library
 
Thank you markros for your reply. The error has gone way, but result is not as I expected (due to my fault of setting up the query). I will need to have another query to get the right result, and will come back here later if anymore help is acquired.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top