skip to Main Content

I Want to select transactions under PL Category 52105 and transaction codes 9007 & 9803, but the results are are picking other transaction codes other than those 2. Where am I getting it wrong?

FROM [Steward].[dbo].[vwNONFUNDED_RECOMP_04] 
   
WHERE PL_CATEGORY_CATEG_STMT IN ('52105') OR PL_CATEGORY_CATEG_STMT IS NULL AND TRANSACTION_CODE_STMT IN ('9007', '9803') AND REVERSAL_MARKER_STMT NOT LIKE ('R')  

order by BOOKING_DATE_STMT

enter image description here

2

Answers


  1. Its the order of precedence that yields everything behind the OR statement to be treated as just that.

    Try the following instead, forcing the order by using brackets:

    WHERE (PL_CATEGORY_CATEG_STMT IN ('52105') OR PL_CATEGORY_CATEG_STMT IS NULL) AND TRANSACTION_CODE_STMT IN ('9007', '9803') AND REVERSAL_MARKER_STMT NOT LIKE ('R')
    

    Note the two brackets around the two statements participating in the OR clause.

    Login or Signup to reply.
  2. Consider rewriting like this:

    FROM [Steward].[dbo].[vwNONFUNDED_RECOMP_04] 
       
    WHERE TRANSACTION_CODE_STMT IN ('9007', '9803') AND REVERSAL_MARKER_STMT NOT LIKE ('R')  AND (PL_CATEGORY_CATEG_STMT IN ('52105') OR PL_CATEGORY_CATEG_STMT IS NULL)
    
    order by BOOKING_DATE_STMT
    

    You might want to look at how you have written your "not like", it should include the wildcards depending on what you want it to achieve

    for example, not like (‘R%’) – where R does not start the Text

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search