Subject UNION not allowed in EXISTS clause?
Author Rick DeBay
The select in the not-exists clause runs fine on its own. When it's
part of an exists or not-exists clause, it fails with the given error.

INSERT INTO CLAIMAUDIT (RXCLAIMNBR,RXCLAIMSEQ,AUDITSTATUS,REASON)
SELECT DISTINCT 5,123,0,'TEST'
FROM CLAIMAUDIT
WHERE NOT EXISTS
(SELECT DATESBM FROM CLAIMSPAIDREVERSED WHERE RXCLAIMNBR='5' AND
CLMSEQNBR<=123 and CLAIMSTS='X'
UNION
SELECT CHANGED FROM CLAIMAUDIT WHERE RXCLAIMNBR=5 AND
RXCLAIMSEQ=123 AND REASON='TEST')

Dynamic SQL Error SQL error code = -104 Token unknown - line 6, char 6
UNION

Rick DeBay
Senior Software Developer
RxStrategies.net