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 2005 Forums
 Transact-SQL (2005)
 Select Query

Author  Topic 

anishap
Yak Posting Veteran

61 Posts

Posted - 2010-09-17 : 15:54:23
I have a table with column TYPE1, TYPE2, TYPE3, TYPE4. I want to select rows that doesn't have 'METALS' in any of these 4 columns.

I tried to query using 'OR' OPERATOR but it won't work.

Can any one help me with this?

Thanks

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2010-09-17 : 15:59:41
you want a AND operator not OR

Slect * from mytable where
not type1 = 'METALS'
and
not type2 = 'METALS'
and
not type3 = 'METALS'
and
not type4 = 'METALS'



Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-18 : 09:14:22
i prefer using column <> rather than not column =

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rohitvishwakarma
Posting Yak Master

232 Posts

Posted - 2010-09-20 : 05:39:31
SELECT * FROM mytable WHERE
type1 <> 'METALS' AND
type2 <> 'METALS' AND
type3 <> 'METALS' AND
type4 <> 'METALS'
Go to Top of Page
   

- Advertisement -