Rick_McGee
Technical User
I inherited a query that needs modifying. The query seems standard with a 'Select field1, field2 from TABLE_A where blah, blah, blah....'
Then it has the following statements as a part of the query:
I cannot understand what the SUM(CASE) statements are doing. They seem redundant, but it's a query that's been used for sometime. Can someone please shed some light on what these statements are accomplishing? Thank you.
Then it has the following statements as a part of the query:
Code:
HAVING (SUM(CASE
WHEN S.LVLP1 NOT IN ('A','B','C','D') THEN 1
ELSE 0 END)
+ SUM(CASE
WHEN S.LVLP1 IN('A','B','C','D') THEN 1
ELSE 0 END)
¬= SUM(CASE
WHEN S.LVLP1 NOT IN('A','B','C','D') THEN 1
ELSE 0 END))
AND SUM(CASE
WHEN S.LVLP1 IN('A','B','C','D') THEN 1
ELSE 0 END) > 0
I cannot understand what the SUM(CASE) statements are doing. They seem redundant, but it's a query that's been used for sometime. Can someone please shed some light on what these statements are accomplishing? Thank you.