abebea
abebea

Reputation: 1

Example Case or IF Statement in SQL

I have a query as follows:

 SELECT A.BELEGNR, A.BEZEICH, A.PREIS, A.BUDATUM, A.P_RG_BEZAH, B.BEDINGUNG, A.LIEFERANT,
 A.NAME, A.KENN_FREI, A.KURS, A.VALUTA_DAT
 FROM   A
 LEFT OUTER JOIN B ON B.BED_NR=A.ZBD AND A.SPRACHE=B.SPRACHE
 WHERE
 A.P_RG_BEZAH=0  AND A.KENN_FREI<>'E'
 AND
 if A.GESCH_BER IN (002,005) and A.LIEFERANT not in ('600099','601922')
 else A.LIEFERANT not in ('600299','601519') and A.VALUTA_DAT > getdate()

I would like to use Case or IF Statement for the last part:

if A.GESCH_BER IN (002,005) and A.LIEFERANT not in ('600099','601922')
else A.LIEFERANT not in ('600299','601519') and A.VALUTA_DAT > getdate()

Tried many options, and not knowing further.

Thank you.

Upvotes: 0

Views: 38

Answers (1)

MarEll
MarEll

Reputation: 296

you should use AND/OR like this:

 WHERE A.P_RG_BEZAH=0  
   AND A.KENN_FREI<>'E'
   AND ((A.GESCH_BER IN (002,005) and A.LIEFERANT not in ('600099','601922')) OR 
        (A.LIEFERANT not in ('600299','601519') and A.VALUTA_DAT > getdate()))

Upvotes: 1

Related Questions