This topic is locked

SQL query not working

11/17/2006 6:09:51 AM
ASPRunnerPro General questions
I
intour author

Hello,
My sql query appears us not giving the desired results. I am trying to exclude certain brands and deleted products. the brands are in the field - IDBrand and they are identified by numbers 1,2,14 and 28. The deleted products have a value of -1 in the removed field and the live ones have a value of 0. This is what I tried:

[pcprod_AddWPrice],

[manufacturer],

[category]

From [products]

Where IDBrand <> 1 or 2 or 14 or 28

And removed = 0


but it is returning all products and not excluding the ones I want.
I'm guessing I have this wrong - can anyone help please.
Many thanks
Nigel

Alexey admin 11/17/2006

Nigel,
try this query

...

From [products]

Where

IDBrand<>1 and IDBrand<>12 and IDBrand<>114 and IDBrand<>128

And removed = 0



Here are some useful tutorials where you can learn SQL:

http://www.webcheatsheet.com/sql/interactive_sql_tutorial/

http://www.w3schools.com/sql/

C
clig 11/18/2006

Hello,

My sql query appears us not giving the desired results. I am trying to exclude certain brands and deleted products. the brands are in the field - IDBrand and they are identified by numbers 1,2,14 and 28. The deleted products have a value of -1 in the removed field and the live ones have a value of 0. This is what I tried:
but it is returning all products and not excluding the ones I want.
I'm guessing I have this wrong - can anyone help please.
Many thanks
Nigel


Something like:
SELECT IDBrand, removed

FROM dbo_foo

WHERE (Not (IDBrand=1)) And (Not (IDBrand=2)) And (Not (IDBrand=14)) And (Not (IDBrand=28)) And (removed=0)
would work...

I
intour author 11/19/2006

Hi,
Thanks for the links. I had already done the whole of the W3schools tutorials. These are very useful resources but neither deal with mutliple selections of this kind.
I always seem to get problems with the <> statement and the suggestion you made didn't work.
I'll try the second one here using the 'NOT' statement and let you know how I get on.
Thanks again
Nigel

Sergey Kornilov admin 11/19/2006

Nigel,
take a look at IN and NOT IN operators.

WHERE ID IN (1,2,7,48)
WHERE ID NOT IN (1,2,7,48)