sql - I need a final tweak to this CASE statement -
i have following piece of code:
select case when (acct.nmajorhcode in ('7','16') , det_type not in ('acr', 'adr', 'crn')) or (det_type in ('adr', 'crn') , cr.nmajorhcode < 4 , acct.ntype not in ('a', 'x')) -nl.det_final else nl.det_final this loop through fifteen databases. however, 1 of database operates different business rules and, in above example, final 2 lines need be
then nl.det_final else -nl.det_final i.e signs reversed.
how can case statement behave how want? in english, when clause "make number negative unless db_name() = 'proteus' in case make positive".
similarly, else needs sign reversing.
thank reading.
i'd move out separate expression:
select case when (acct.nmajorhcode in ('7','16') , det_type not in ('acr', 'adr', 'crn')) or (det_type in ('adr', 'crn') , cr.nmajorhcode < 4 , acct.ntype not in ('a', 'x')) -nl.det_final else nl.det_final end * case when db_name() = 'proteus' -1 else 1 end (and, note on terminology - case expression (it computes value), not statement)
Comments
Post a Comment