I am finding difficulty while converting the below case statement into the IF else logic to use it into a constaraint while calculation the below scenario..especially with huge amount of data. I tried implemented at source query level, it work for minimal amount of data.
Code: Select all
CASE WHEN a.Id=2 THEN
COUNT(DISTINCT CASE
WHEN b.code IN ('A','B','C','D') THEN c.item
ELSE NULL
END
) else 0 END as CNT1,
CASE WHEN a.Id=2 THEN
SUM(CASE
WHEN b.code IN ('A','B','C','D') AND c.item IS NULL THEN 1
ELSE 0
END
) ELSE 0 END as CNT2
SUM(CNT1) + SUM(CNT2) AS TOTAL_CNT
Thanks,
S.R