How the hell do I do this in SQL :
Select * from MyTable where F1 = "This" AND F2 = "This" And F3 Between 10000
And 15000 OR F3*10 Between 10000 And 15000
I know it's a strange query. I wont go into any further details but the OR
F3*10 Between 10000 And 15000 is required.
Everything is fine until I add that bleedin "OR F3 *10 Between 10000 And
15000".
How the hell do I nest this ?AND has higher precedence than OR. In situations of confusion, use
brackets.
hth
Quentin
"Poppy" <paul.diamond@.NOSPAMthemedialounge.com> wrote in message
news:unElkkE3DHA.2224@.TK2MSFTNGP10.phx.gbl...
> How the hell do I do this in SQL :
> Select * from MyTable where F1 = "This" AND F2 = "This" And F3 Between
10000
> And 15000 OR F3*10 Between 10000 And 15000
> I know it's a strange query. I wont go into any further details but the OR
> F3*10 Between 10000 And 15000 is required.
> Everything is fine until I add that bleedin "OR F3 *10 Between 10000 And
> 15000".
> How the hell do I nest this ?
>|||Because of the rules of precedence for logical operators
a AND b AND c OR d
is interpreted as
(a AND b AND c) OR d
It looks like you want to put parentheses around the OR'd expressions:
SELECT *
FROM MyTable
WHERE F1 = 'This' AND F2 = 'This'
AND
(F3 BETWEEN 10000 AND 15000 OR F3 BETWEEN 1000 AND 1500)
--
David Portas
--
Please reply only to the newsgroup
--|||WHere should I use the brackets ?
No matter how hard I try it doesnt work.
"Quentin Ran" <ab@.who.com> wrote in message
news:#$PS8qE3DHA.1760@.TK2MSFTNGP10.phx.gbl...
> AND has higher precedence than OR. In situations of confusion, use
> brackets.
> hth
> Quentin
> "Poppy" <paul.diamond@.NOSPAMthemedialounge.com> wrote in message
> news:unElkkE3DHA.2224@.TK2MSFTNGP10.phx.gbl...
> > How the hell do I do this in SQL :
> >
> > Select * from MyTable where F1 = "This" AND F2 = "This" And F3 Between
> 10000
> > And 15000 OR F3*10 Between 10000 And 15000
> >
> > I know it's a strange query. I wont go into any further details but the
OR
> > F3*10 Between 10000 And 15000 is required.
> >
> > Everything is fine until I add that bleedin "OR F3 *10 Between 10000 And
> > 15000".
> >
> > How the hell do I nest this ?
> >
> >
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment