Need SQL help - the code below works fine
SELECT S.ORDOCAMT,
S.SALSTERR,
S.SLPRSNID,
S.SOPNUMBE,
S.DOCDATE,
S.SOPTYPE,
S.CUSTNMBR,
T.CUSTCLAS,
T.CUSTNAME,
T.USERDEF1,
S.SUBTOTAL,
S.DOCAMNT,
S.MRKDNAMT
FROM SOP10100 S
LEFT OUTER JOIN RM00101 T
ON T.CUSTNMBR = S.CUSTNMBR
UNION ALL
SELECT S.ORDOCAMT,
S.SALSTERR,
S.SLPRSNID,
S.SOPNUMBE,
S.DOCDATE,
S.SOPTYPE,
S.CUSTNMBR,
T.CUSTCLAS,
T.CUSTNAME,
T.USERDEF1,
S.SUBTOTAL,
S.DOCAMNT,
S.MRKDNAMT
FROM SOP30200 S
LEFT JOIN RM00101 T
ON T.CUSTNMBR = S.CUSTNMBR
ORDER BY S.SOPNUMBE
GO
but when I try to add a WHERE stmt
SELECT S.ORDOCAMT,
S.SALSTERR,
S.SLPRSNID,
S.SOPNUMBE,
S.DOCDATE,
S.SOPTYPE,
S.CUSTNMBR,
T.CUSTCLAS,
T.CUSTNAME,
T.USERDEF1,
S.SUBTOTAL,
S.DOCAMNT,
S.MRKDNAMT
FROM SOP10100 S
WHERE S.SALESTERR = 'JA'
LEFT OUTER JOIN RM00101 T
ON T.CUSTNMBR = S.CUSTNMBR
UNION ALL
SELECT S.ORDOCAMT,
S.SALSTERR,
S.SLPRSNID,
S.SOPNUMBE,
S.DOCDATE,
S.SOPTYPE,
S.CUSTNMBR,
T.CUSTCLAS,
T.CUSTNAME,
T.USERDEF1,
S.SUBTOTAL,
S.DOCAMNT,
S.MRKDNAMT
FROM SOP30200 S
WHERE S.SALESTERR = 'JA'
LEFT JOIN RM00101 T
ON T.CUSTNMBR = S.CUSTNMBR
ORDER BY S.SOPNUMBE
GO
i get this error message:
Msg 156, Level 15, State 1, Line 19
Incorrect syntax near the keyword 'LEFT'.
Msg 156, Level 15, State 1, Line 41
Incorrect syntax near the keyword 'LEFT'.
It doesn't make sense - probably something stupid but I don't see it
*This post is locked for comments
I have the same question (0)