943,796 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 6822
  • MS SQL RSS
Aug 24th, 2006
0

Problem With "Where" with boolean type

Expand Post »
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

MS SQL Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
blacklocist is offline Offline
87 posts
since Apr 2006
Aug 24th, 2006
0

Re: Problem With "Where" with boolean type

I used this syntax and it work perfectly.

MS SQL Syntax (Toggle Plain Text)
  1.  
  2. USE MTRTRK
  3. SELECT * FROM MOTORS
  4. WHERE CUSTOMERID IN ('52', '72', '62') AND CHKCANCEL = '0' AND DITD IS NULL
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
blacklocist is offline Offline
87 posts
since Apr 2006
Sep 12th, 2006
1

Re: Problem With "Where" with boolean type

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'))
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Sep 13th, 2006
0

Re: Problem With "Where" with boolean type

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


Click to Expand / Collapse  Quote originally posted by campkev ...
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'))
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
blacklocist is offline Offline
87 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: SQL query
Next Thread in MS SQL Forum Timeline: Fulltext search with MS SQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC