Case stmt

Database
Enthusiast

Case stmt

Hi all!
I have this case statmt and I would like any suggestions on how to simplify this further.

select A.CNCT as c1
from table A
where (
case
when A.CD = 'a' then 'A. Hgh'
else 'J. Unkwn'
end = 'A. Hgh'
or case
when A.CD = 'b' then 'B. Aff I'
else 'J. Unkwn'
end = 'B. Aff I'
or case
when A.CD = 'u' then 'I. Uncl'
else 'J. Unkwn'
end = 'I. Uncl'
or case
when A.CD = 'a' then 'A. Hgh'
when A.CD = 'b' then 'B. Aff I'
when A.CD = 'c' then 'C. Aff II'
when A.CD = 'd' then 'D. Mss Mkt Pot Hgh Wrth'
when A.CD = 'e' then 'E. Mss Mkt Pot Aff I'
when A.CD = 'f' then 'F. Mss Mkt Pot Aff II'
when A.CD = 'g' then 'G. Emg Aff'
when A.CD = 'h' then 'H. Mss Mkt'
when A.CD = 'u' then 'I. Uncl'
when A.CD = 't' then 'K Ttn Only'
else 'J. Unkwn'
end = 'J. Unkwn'
or case
when A.CD = 't' then 'K Ttn Only'
else 'J. Unkwn'
end = 'K Ttn Only' )

Thanks!!
2 REPLIES
Junior Contributor

Re: Case stmt

This seems to be the same as
WHERE A.CD IN('a','b','u','t')
OR A.CD NOT IN ('a','b','c','d','e','f','g','h','u','t')

which can be further simplified to
WHERE A.CD NOT IN ('c','d','e','f','g','h')

Dieter

Dieter
Enthusiast

Re: Case stmt

Thanks aq lot Dieter!!!!