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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Logic

Author  Topic 

pazzy11
Posting Yak Master

145 Posts

Posted - 2008-03-13 : 10:01:54
I have a logic problem,

I am selecting from a table
[CODE]
Select * from TAB_A
where state not in (1,4)
and create_date < '2008-01-01'
and
(
(x != 2 and y != 1 and z != 4) or
(x != 6 and y != 3 and z != 1) or
(x != 8 and y != 0 and z != 9)
)
[/CODE]

then for example i am getting results where x,y and z is equal to one
or more of above combinations ?

Now i vaguely remember that using or with a != messes up the logic ?
if so can i use an NOR ? does it exist ?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-03-13 : 10:11:26
I believe it's the OR that's messing you up. x=2,y=1,z=4 can be returned since it satisfies the last 2 conditions. Change the OR to AND.


Jim
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2008-03-13 : 10:19:42
Changing the the OR to AND returns 0 results and i know there are cases that should be returned..
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 10:20:29
Ok, then. Please read and follow the advice in this blog post so that we can mimic your environment and testdata.
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2008-03-13 : 11:08:34
ok now i realise, OR and != is a flaw in logic ....

so i can use OR and = and use another table...
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-03-13 : 11:13:16
pazzy11 -- no one can help you with your logic if you cannot express to us exactly what it should be. We can't look at a boolean expression that doesn't work and guess as to what it is supposed to be doing. This is not a SQL problem at all, just a logic problem. be sure you fully understand how AND,OR,=,!=, etc work.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -