Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Problem with CASE WHEN statement - response (14) by dnoeth

$
0
0

Hi Anu,
the first WHEN in a CASE which evaluates to TRUE will be used, it's not doing a kind of best-match.
The rule of thumb is to define the most restrictive condition first.
You could rewrite it to:

CASE
  WHEN TYPE_CD IN ('01','02') THEN 1
  WHEN TYPE_cD IN ('03') AND STS_CD<>'N' THEN 1
  ELSE 0
END as CNT

or

CASE
  WHEN TYPE_CD IN ('01','02') 
    OR (TYPE_cD IN ('03') AND STS_CD<>'N') THEN 1
  ELSE 0
END as CNT

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>