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!
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)
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.