Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nestled where statements with and or and <>

Status
Not open for further replies.

Luvsql

Technical User
Apr 3, 2003
1,179
CA
If my statement only has the where A<>B it works, however, if I place a nestled (A<>B or A<>C) it ignores the both restrictions. I cannot seem to figure out how to do this in a single select.

SELECT * FROM Table x
WHERE Z = 'value'
and Y = 'value'
AND ( (A<>B) or (A<>isnull(C,0)) )
and T='value'
 
What do you mean with ignore? (A<>B OR A<>C) is always true, if B<>C, because even if A is B or C, which makes either A<>B untrue or A<>C untrue, the other condition is fullfilled.

Do you reall want to OR these conditions?

In an example you'll see how your logic is broken:
let B=1, C=2, then even 1 or 2 are not both 1 and 2, so any A will fullfill this condition and it won't restrict the sql result in any way.

Bye, Olaf.
 
Maybe you need AND :)
Code:
...
AND (A<>B AND A<>isnull(C,0))

or
Code:
..
AND (A NOT IN (B, isnull(C,0)))




Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top