Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Data Contamination . . .

Author  Topic 

binggeli
Starting Member

20 Posts

Posted - 2005-11-23 : 09:54:47
Why does this query return data from other ClientID's as well?

SELECT TOP 111 * FROM Users WHERE ClientID = 'INGBANK'
AND TermDate IS NULL
AND isGroup IS NULL OR isGroup = 0



But this one gives me the correct data
(only data from the specified ClientID):

SELECT TOP 111 * FROM Users WHERE ClientID = 'INGBANK'
AND TermDate IS NULL
AND (isGroup IS NULL OR isGroup = 0)



What am I doing wrong in the first query?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-23 : 09:57:34
First query is treated as

SELECT TOP 111 * FROM Users WHERE ClientID = 'INGBANK'
AND (TermDate IS NULL
AND isGroup IS NULL) OR isGroup = 0



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

binggeli
Starting Member

20 Posts

Posted - 2005-11-23 : 10:22:31
The light came on.


Thank you very much!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-23 : 23:46:03
If there are lot of ANDs and ORs then better to use braces to get the proper result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -