Selvam
Selvam

Reputation: 1093

Teradata SQL - Where clause and conditions depending on conditions

enter image description here

Note- not all columns are listed here in the Master Table for brevity. Psuedo code of the where clause -

enter image description here enter image description here

My where clause goes like this (with some selected conditions) -

  1. customer_country in ('A','B','C','D') AND
  2. ship_country = 'A' AND customer_number <> 'A2' OR
  3. ship_country = 'B' AND customer_number <> 'B2' OR
  4. ship_country = 'C' AND customer_number NOT IN ('C1', 'C2') AND
  5. ship_date between dates.

But this appears to give incorrect answer. Perhaps something is wrong with the logic. Please advice.

Upvotes: 0

Views: 3725

Answers (1)

D-Shih
D-Shih

Reputation: 46219

You can try this

SELECT * 
FROM [MASTER]
WHERE 
    Ship_country in ('A','B','C','D')
AND
    (   
        (customer_number <> 'A2')
    OR
        (customer_number <> 'B2')
    OR
        (customer_number NOT IN ('C1', 'C2'))
    )

Upvotes: 2

Related Questions