I have 2 tables, "Payable" and "Payable_Line" which contains detail information. I want a query to use max if one of the field in my query is "Null". However, I can't get it to work correctly.
Query output result:
SELECT P.VOUCHER_ID, P.INVOICE_ID, P.TOTAL_AMT,
CASE WHEN PL.PO_ID IS NULL THEN MAX(PL.PO_ID) ELSE PL.PO_ID END PO_ID
FROM PAYABLE P LEFT OUTER JOIN PAYABLE_LINE PL
ON P.VOUCHER_ID = PL.VOUCHER_ID
GROUP BY P.VOUCHER_ID, P.INVOICE_ID, P.TOTAL_AMT, PL.PO_ID
Am I doing something wrong? Basically wanting to input my max value in the "Null" field for PO_ID.