I am writing this SQL statement from a Delphi program to our AS400. We have an internal Delphi program that works similar to 'Query Analyzer' that allows us to see the results of the query. I have this query:
Code:
SELECT JURNUM AS JURNUM, LASTNAME, FIRSTNAME, SSN,
STATUSCD, DOB, 'JMS' AS TYPE
FROM JMPMAIN WHERE TERMDATE >= '19990911'
UNION
SELECT 0 AS JURNUM, SUBSTRING(NAME, 1, POSITION(',' IN NAME) - 1) AS LASTNAME, SUBSTRING(NAME, POSITION(',' IN NAME) + 1) AS FIRSTNAME, SSN,
STATUS AS STATUSCD, '' AS DOB, 'AS4' AS TYPE
FROM CMLIB/CMPJURY WHERE APPRDAT >= 19990911
ORDER BY LASTNAME[code]
When I run each query individually, I get the expected results, but when I try to run the UNION query I get an error:
"Invalid Expression. SQL System Error."
Does anyone have any idea why this query won't work together when it works separately?
Thanks for any insight!
Leslie