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
2
Answers
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:
Note the two brackets around the two statements participating in the
OR
clause.Consider rewriting like this:
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