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.
Author |
Topic |
ann
Posting Yak Master
220 Posts |
Posted - 2012-03-20 : 14:44:37
|
I always get this wrong. This is what my query looks like:SELECT AcctID, Status, queuedTo FROM Acctswhere queuedto = 4 AND (Status != 'Canceled' OR status != 'sold'))All I want are all the status's not equal to Canceled or Sold, but no matter how I write this, I always still end up with results with eitherCan anyone help?Thanks  |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-03-20 : 14:52:36
|
[code]WHERE queuedto = 4 AND STATUS NOT IN ( 'Canceled' ,'sold')[/code] |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
ann
Posting Yak Master
220 Posts |
Posted - 2012-03-20 : 15:03:55
|
Neither of those results are right, because they ignore Null values.Yes, I should have given example, here it is:Table:AcctID Status QueuedTo1 Null 42 Active 43 Sold 54 Sold 45 Canceled 4Results wanted:1, Null, 42, Active, 4 |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-03-20 : 15:09:10
|
[code]WHERE queuedto = 4 AND (STATUS NOT IN ( 'Canceled' ,'sold') OR STATUS is NULL);[/code] |
 |
|
ann
Posting Yak Master
220 Posts |
Posted - 2012-03-20 : 15:10:36
|
Thanks - that's it |
 |
|
|
|
|
|
|