Hi All - I am extremely confused about the SQL below. Can some one please help me and reading this SQL below. Does the WHEN NOT EXIST and NOT EQUAL TO cancel each other? I have a "validation status" column and my case statement doesn't yield the correct results that I am trying to pull based on the match_status_flag column.
CASE
WHEN NOT EXISTS
(SELECT match_status_flag
FROM apps.ap_invoice_distributions_all aida
WHERE aida.org_id =81
AND aida.invoice_id = aia.invoice_id
AND NVL(match_status_flag,'N') != 'A'
)
THEN 'Validated'
WHEN NOT EXISTS
(SELECT match_status_flag
FROM apps.ap_invoice_distributions_all aida
WHERE aida.org_id =81
AND aida.invoice_id = aia.invoice_id
AND NVL(match_status_flag,'N') != 'N'
)
THEN 'Never Validated'
ELSE 'Needs Revalidation'
END validation_status