Q:

I need a final tweak to this CASE statement

I have the following piece of code:
SELECT CASE WHEN (ACCT.NMAJORHCODE IN ('7','16') 
AND DET_TYPE NOT IN ('ACR', 'ADR', 'CRN'))
OR (DET_TYPE IN ('ADR', 'CRN') AND CR.NMAJORHCODE < 4 AND ACCT.NTYPE NOT IN ('A', 'X'))
THEN -NL.DET_FINAL
ELSE NL.DET_FINAL

This will loop through fifteen databases.  However, one of the database operates to slightly different business rules and, in the above example, the final two lines need to be
THEN NL.DET_FINAL
ELSE -NL.DET_FINAL

i.e the signs are reversed.
How can I get my CASE statement to behave how I want?  In English, when I get to the THEN clause it would be "make the number negative unless DB_NAME() = 'Proteus' in which case make it positive".
Similarly, the ELSE needs sign reversing.
Thank you for reading. 

A:

I'd move it out into a separate expression:
SELECT CASE WHEN (ACCT.NMAJORHCODE IN ('7','16') 
AND DET_TYPE NOT IN ('ACR', 'ADR', 'CRN'))
OR (DET_TYPE IN ('ADR', 'CRN') AND CR.NMAJORHCODE < 4 AND ACCT.NTYPE NOT IN ('A', 'X'))
THEN -NL.DET_FINAL
ELSE NL.DET_FINAL END * CASE WHEN DB_NAME() = 'PROTEUS' THEN -1 ELSE 1 END

(And, a note on terminology - CASE is an expression (it computes a value), not a statement)

