Check a number of columns against multiple values

I want to check a number of 'columns' in a table to see if their value
equals either 4 or 5.

That is,
select Count(*) from myTable
WHERE step = 100 AND (
a=4 Or a=5 Or
b=4 Or b=5 Or
c=4 Or c=5 Or
d=4 Or d=5 Or
e=4 Or e=5 Or
f=4 Or f=5)

(there's more than this)

I thought there must be a better way of doing it!
ben h [ Do, 06 Juli 2006 09:42 ] [ ID #1382303 ]

Re: Check a number of columns against multiple values

"ben h" <hairyguard-newsgroups [at] yahoo.co.uk> wrote in message
news:Opnt1%23MoGHA.4124 [at] TK2MSFTNGP03.phx.gbl...
> I want to check a number of 'columns' in a table to see if their value
> equals either 4 or 5.
>
> That is,
> select Count(*) from myTable
> WHERE step = 100 AND (
> a=4 Or a=5 Or
> b=4 Or b=5 Or
> c=4 Or c=5 Or
> d=4 Or d=5 Or
> e=4 Or e=5 Or
> f=4 Or f=5)
>
> (there's more than this)
>
> I thought there must be a better way of doing it!

AND 4 IN (a,b,c,d,f) OR 5 IN (a,b,c,d,e,f)
Anthony Jones [ Do, 06 Juli 2006 19:18 ] [ ID #1382312 ]

Re: Check a number of columns against multiple values

> AND 4 IN (a,b,c,d,f) OR 5 IN (a,b,c,d,e,f)
>

Ah-hah, I did try that, but maybe I didn't do it right. Will try again.
Thanks.
ben h [ Fr, 07 Juli 2006 05:21 ] [ ID #1383573 ]
Webserver » microsoft.public.inetserver.asp.db » Check a number of columns against multiple values

Vorheriges Thema: Incomplete retrieval from SYBASE using ADO
Nächstes Thema: Accessing Remote FoxPro table