Showing posts with label hell. Show all posts
Showing posts with label hell. Show all posts

Monday, March 26, 2012

query from hell

if when the data is in mdb format the below query works

SELECT *
FROM [rating & px Tgt History]
WHERE ((([from] Like "*Init*" And [action] Like "*Target*")=False and deleted=false));

but when the access linked to backend is sql server via odbc i get this

ODBC call failed
{microsoft][odbc sql server driver][sql server]line 1:incorrect syntax near '=' #170

One thing that jumps out at me is the asterisk * needs to be a %... ex: Like '%Init%' ... the only other thing that looks wrong is you are using double quotes.. try using single quotes.

Monday, February 20, 2012

Query And Or Problems (Nesting)

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...
quote:

> How the hell do I do this in SQL :
> Select * from MyTable where F1 = "This" AND F2 = "This" And F3 Between

10000
quote:

> 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 ?
>
|||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...
quote:

> 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...
> 10000
OR[QUOTE]
>
|||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
--

Query And Or Problems (Nesting)

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 ?
> >
> >
>