Reputation: 600
I am trying to use or statement in SQL but it's not producing the results I want.
Here I want to expand the code so they are either 0012 or 0005 with the rest of conditions being the same. Here is the codes I am trying to modify, and I just added second line but it doesn't get what I wanted.
WHERE pr.code = '0005'
OR pr.code = '0012'
AND p.effdate > '2/8/2017'
AND p.pnum not like 'R%'
AND p.status like '6'
Upvotes: 1
Views: 95
Reputation: 5850
You need to add parenthesis:
WHERE (pr.code = '0005' OR pr.code = '0012')
AND p.effdate > '2/8/2017'
AND p.pnum not like 'R%'
AND p.status like '6'
And in this case, as @MiloBellano mentioned in his answer, you can prevent such errors by using IN
operator:
WHERE pr.code IN ('0005', '0012')
AND p.effdate > '2/8/2017'
AND p.pnum not like 'R%'
AND p.status like '6'
Upvotes: 4
Reputation: 396
WHERE (pr.code = '0005'
OR pr.code = '0012')
AND p.effdate > '2/8/2017'
AND p.pnum not like 'R%'
AND p.status like '6'
But I think that
pr.code in ('0005','0012')
AND p.effdate > '2/8/2017'
AND p.pnum not like 'R%'
AND p.status like '6'
looks nicer and probably faster
Upvotes: 1
Reputation: 666
WHERE (pr.code = '0005'
OR pr.code = '0012')
AND p.effdate > '2/8/2017'
AND p.pnum not like 'R%'
AND p.status like '6'
Upvotes: 0