Logical Operators

• lbrigham (5/24/2012)

Add me to this list too. I answered OR having higher precedent than AND because it doesn't matter what the evaluation of one side of the OR is if the other side evaluates true therefore the OR is of a higher "precedent", but I didn't take into account how Microsoft defines "precedent". Oh well.

It would be enormously difficult to write a parser that would change the precedence according to the command being evaluated. For example, if you had the following construct:

A AND B OR C AND D

In this case you *do* have to evaluate at least one and possibly both of the AND conditions before you can determine what the result of the OR is, but how is the parser supposed to realise that? It makes more sense to both computer and human to always have the same order of precedence for these operators, rather than trying to best guess which way to evaluate things depending on the command.

• Hence the invention of parenthesis... ๐

PeteK
I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.

• lbrigham (5/24/2012)

Add me to this list too. I answered OR having higher precedent than AND because it doesn't matter what the evaluation of one side of the OR is if the other side evaluates true therefore the OR is of a higher "precedent", but I didn't take into account how Microsoft defines "precedent". Oh well.

Well, reading glasses (so that you can distinguish "precedence" from "precedent") and a decent English dictionary (so that you can discover that Microsoft assigns exactly the same meaning to "precedence" as do English speakers in general) would probably help.

I suppose that's just a less polite way of saying what Paul Knibbs said most of a coupleof posts back, but your comment realy got my goat and I thought some additional sting was needed.

Tom

• Right, I misread the question, and probably could've explained myself better as opposed to confusing the definition of precedence and laying blame where it wasn't deserved when it was actually me who misunderstood the real definition. As far as precedence and order of how the evaluation occurs, it makes sense that the ANDs are evaluated first, thus are higher precedence than the ORs, which I understood, and I guess I was thinking which is of higher "importance" or something... I don't know, but I was dwelling on the fact that it doesn't matter for a given OR what side evaluates to TRUE or FALSE if one side is true so in the case of 1 AND 0 OR 1, the OR was of higher precedence because the 1 AND 0 didn't matter. Oh well. It was my mistake and my stupidity. Thanks and sorry about your goat.

• L' Eomot Inversรฉ (5/25/2012)

lbrigham (5/24/2012)

Add me to this list too. I answered OR having higher precedent than AND because it doesn't matter what the evaluation of one side of the OR is if the other side evaluates true therefore the OR is of a higher "precedent", but I didn't take into account how Microsoft defines "precedent". Oh well.

Well, reading glasses (so that you can distinguish "precedence" from "precedent") and a decent English dictionary (so that you can discover that Microsoft assigns exactly the same meaning to "precedence" as do English speakers in general) would probably help.

I suppose that's just a less polite way of saying what Paul Knibbs said most of a coupleof posts back, but your comment realy got my goat and I thought some additional sting was needed.

My dictionary offers

"The condition of being considered more important than someone or something else; priority in rank."

as the first definition. So I would suggest that the sting was absolutely not needed.

• ronmoses (5/24/2012)

The only reason I had to think about it a while is that I would never combine AND and OR without parentheses, so that fact was a bit dusty in my brain. Yeah, it's something you should know, but it should also be something you don't have to worry about.

ron

I have to agree. When I am using both OR and AND I use parens to ensure the proper order of evaluation.

• It sure was an easy question and a fact anyone using WHERE clauses should know. The difficulty is on understanding the question and reading carefully.

Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

How to post data/code on a forum to get the best help: Option 1 / Option 2
• Easy one!

• nice question

+1 ๐

_______________________________________________________________
http://www.sqlservercentral.com/articles/Best+Practices/61537/

I can't believe that 21% have currently got it completely wrong, thinking that OR has precedence over AND! Hopefully they're just all misunderstanding what 'precedence' means ๐

I'm one of these 21%.

--
Dineshbabu
Desire to learn new things..

• ronmoses (5/24/2012)

The only reason I had to think about it a while is that I would never combine AND and OR without parentheses, so that fact was a bit dusty in my brain. Yeah, it's something you should know, but it should also be something you don't have to worry about.

ron

Yeah me too.. If i'm using OR in WHERE clause and if it has more than one filter condition i will do it inside parentheses.

So i know how AND & OR will work.. I never bothered abt precedence..

--
Dineshbabu
Desire to learn new things..

Viewing 11 posts - 31 through 40 (of 40 total)