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)
 Multiple column check

Author  Topic 

nshankar
Starting Member

9 Posts

Posted - 2008-03-01 : 03:38:30
I am trying to query multiple columns for a specific value. I have 8 columns (values are either 1 or 0)and I want to query the table to find out which rows contain zero's in ALL of the 8 columns. Whats the best way to do this? I can create a lenghty select statement where column1 =0 and column2 =0 and column3=0 and column4 =0 and column5 =0 .... etc. I was wondering if there was an easier way to do this?


Thanks in Advance
Shankar.N

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-01 : 09:18:31
WHERE 1 NOT IN (Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8)

Also see
http://weblogs.sqlteam.com/peterl/archive/2007/09/28/Save-some-time-and-key-typing.aspx


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

nshankar
Starting Member

9 Posts

Posted - 2008-03-03 : 00:28:50
Hi

Thanks a lot. Got it exactly.

Cheers
Go to Top of Page
   

- Advertisement -