1

Can you please help me out with the below query?

I need to extract from column VAL_DT only items with date older than today's date but this rule should not apply to items that contain the following wordings in column MVT_DS: "NOSTRO", "SCREV", "SCRIN", "MAN".

here is my attempt

SELECT * FROM table_name 
WHERE VAL_DT < CURRENT DATE  IF MVT_DS <> 'NOSTRO' AND MVT_DS <> 'SCREV' AND MVT_DS <> 'SCRIN' AND MVT_DS <> 'MAN'
  • 1
    IF is invalid in the WHERE clause. See if you can use the logical OR somehow. – mustaccio Mar 17 '16 at 14:20
3

I would amend your logic to:

WHERE 
    VAL_DT < CURRENT DATE 
    OR 
    (
        MVT_DS = 'NOSTRO' 
        OR MVT_DS = 'SCREV' 
        OR MVT_DS = 'SCRIN' 
        OR MVT_DS = 'MAN'
    )

or even

WHERE 
    VAL_DT < CURRENT DATE 
    OR MVT_DS IN (
      'NOSTRO', 'SCREV', 'SCRIN', 'MAN'
    )

I changed it so that VAL_DT should be earlier than the current date or the other field should equal the respective values. So to get a "true" result - either VAL_DT < "current date" or MVT_DS is one of those values. If it's one of those values it will therefore bypass the "current date" check, effectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.