0

Hi all,
Well I am still new to sql to getting better and better with each query. Now this one has me completley stumped.

Here is the query

SELECT * FROM MOTORS
WHERE     (CHKCANCEL = '0') AND (DITD IS NULL) AND (CUSTOMERID = '52') OR
                      (CUSTOMERID = '62') OR
                      (CUSTOMERID = '72')

This return 37 rows but there is two rows that have CHKCANCEL = 1

Any Ideas??

Thx

2
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by blacklocist
0

I used this syntax and it work perfectly.

use MTRTRK
SELECT * FROM MOTORS
WHERE CUSTOMERID in ('52', '72', '62') and CHKCANCEL = '0' and DITD IS NULL
1

the problem with you original query was precedence

what you need is

WHERE (CHKCANCEL = '0') AND (DITD IS NULL) AND( (CUSTOMERID = '52') OR
(CUSTOMERID = '62') OR
(CUSTOMERID = '72'))

0

Thanks I need to learn the importance of ( and )
THX!!

the problem with you original query was precedence

what you need is

WHERE (CHKCANCEL = '0') AND (DITD IS NULL) AND( (CUSTOMERID = '52') OR
(CUSTOMERID = '62') OR
(CUSTOMERID = '72'))

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.