Problem With "Where" with boolean type

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2006
Posts: 88
Reputation: blacklocist is an unknown quantity at this point 
Solved Threads: 2
blacklocist blacklocist is offline Offline
Junior Poster in Training

Problem With "Where" with boolean type

 
0
  #1
Aug 24th, 2006
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

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


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

Any Ideas??

Thx
Last edited by blacklocist; Aug 24th, 2006 at 3:25 pm. Reason: Forgot select command in the example
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 88
Reputation: blacklocist is an unknown quantity at this point 
Solved Threads: 2
blacklocist blacklocist is offline Offline
Junior Poster in Training

Re: Problem With "Where" with boolean type

 
0
  #2
Aug 24th, 2006
I used this syntax and it work perfectly.

  1.  
  2. USE MTRTRK
  3. SELECT * FROM MOTORS
  4. WHERE CUSTOMERID IN ('52', '72', '62') AND CHKCANCEL = '0' AND DITD IS NULL
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Problem With "Where" with boolean type

 
1
  #3
Sep 12th, 2006
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'))
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 88
Reputation: blacklocist is an unknown quantity at this point 
Solved Threads: 2
blacklocist blacklocist is offline Offline
Junior Poster in Training

Re: Problem With "Where" with boolean type

 
0
  #4
Sep 13th, 2006
Thanks I need to learn the importance of ( and )
THX!!


Originally Posted by campkev View Post
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'))
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC