Keyword UNION not expected
I am trying to get the following union query to process on my coldfusion site:
<cfquery name="committee_record"
datasource="AS400a CMTLIB"
maxrows=100
dbtype="ODBC">
SELECT MBRESMPF.MBMID,
MBRESMPF.MBCYR,
MBRESMPF.MBCCD,
MBRESMPF.MBDCD,
UCase(COMITEPF.CMNAM) AS COM,
MBRESMPF.MBMRC,
UCase(RANKSPF.RKDSC) AS Rank,
MBRESMPF.MBRPT,
MBRESMPF.MBESC,
MBRESMPF.MBERP,
UCase(DIVISNPF.DVNAM) AS DIV
FROM MBRESMPF INNER JOIN RANKSPF ON MBRESMPF.MBMRC = RANKSPF.RKCDE LEFT JOIN COMITEPF ON MBRESMPF.MBCYR = COMITEPF.CMCYR AND MBRESMPF.MBCCD = COMITEPF.CMCCD AND MBRESMPF.MBDCD = COMITEPF.CMDCD LEFT JOIN DIVISNPF ON MBRESMPF.MBDYR = DIVISNPF.DVDYR AND MBRESMPF.MBDCD = DIVISNPF.DVDCD
WHERE MBRESMPF.MBMRC <> 'ORCDVPRN4' AND MBRESMPF.MBMRC <> 'ORCIPDRNS' AND MBMID = #id_number#
ORDER BY MBRESMPF.MBMID, MBRESMPF.MBCYR DESC
UNION SELECT MBRESMPF.MBMID,
MBRESMPF.MBCYR,
MBRESMPF.MBDCD,
MBRESMPF.MBDCD,
UCase(DIVISNPF.DVNAM) AS COM,
MBRESMPF.MBMRC,
UCase(RANKSPF.RKDSC) AS Rank,
MBRESMPF.MBRPT,
MBRESMPF.MBESC,
MBRESMPF.MBERP,
UCase(DIVISNPF.DVNAM) AS DIV
FROM MBRESMPF INNER JOIN RANKSPF ON MBRESMPF.MBMRC = RANKSPF.RKCDE LEFT JOIN DIVISNPF ON MBRESMPF.MBDYR = DIVISNPF.DVDYR AND MBRESMPF.MBDCD = DIVISNPF.DVDCD
WHERE MBRESMPF.MBMRC = 'ORCDVPRN4' OR MBRESMPF.MBMRC = 'ORCIPDRNS' AND MBMID = #id_number#
ORDER BY MBRESMPF.MBMID, MBRESMPF.MBCYR DESC
</cfquery>
But I receive the following error message:
Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)
[IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0199 - Keyword UNION not expected. Valid tokens: FOR USE SKIP WAIT WITH FETCH OPTIMIZE.
The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (19:1) to (22:23).
This query works for me no problem in Microsoft Access. Anyone have any suggestions?
Thank you!
