Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Logic Precedence


Logic Precedence

Author
Message
twin.devil
twin.devil
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1366 Visits: 2594
very good question for the beginners to understand what OR , AND does.

Thanks for sharing ..
david.wright-948385
david.wright-948385
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1059 Visits: 963
Always add brackets when mixing operators. Even if you know the rules, brackets make a calculation less prone to misunderstanding.
kupy
kupy
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1074 Visits: 2647
david.wright-948385 (2/12/2014)
Always add brackets when mixing operators. Even if you know the rules, brackets make a calculation less prone to misunderstanding.

+1
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5743 Visits: 7123
david.wright-948385 (2/12/2014)
Always add brackets when mixing operators. Even if you know the rules, brackets make a calculation less prone to misunderstanding.

Parenthesis prevent uncertainty (and possible misunderstanding)

Thanks for the easy one today, Steve

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Ed Wagner
Ed Wagner
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10188 Visits: 9535
It was a simple question, but nonetheless a good one. How many times have we all been tripped up somewhere and spent hours on it, only to find that the problem was something so simple that we don't even want to admit it to ourselves? Always good to keep the basics in mind, no matter how far back they get. ;-)


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Toreador
Toreador
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2401 Visits: 8054
Didn't know whether OR or AND had priority, so guessed (correctly :-) )
It's not something I've ever really needed to know, doesn't everyone use brackets in cases like this, to make it clear what is meant?
sknox
sknox
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2028 Visits: 2705
david.wright-948385 (2/12/2014)
Always add brackets when mixing operators. Even if you know the rules, brackets make a calculation less prone to misunderstanding.

Until you have several layers of brackets, at which point pairing them up can become as difficult as parsing the text. This can be alleviated by formatting, e.g:

WHERE
(
(a = b)
OR
(b = c)
)
AND
(
(c = d)
OR
(
(d = e)
AND
(e = f)
)
)


as opposed to

WHERE ((a = b) OR (b
= c)) AND ((c = d) OR (
(d = e) AND (e = f)))



The latter, of course, being the type of code outputted by Microsoft's query designers on a regular basis...
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21017 Visits: 18258
twin.devil (2/12/2014)
very good question for the beginners to understand what OR , AND does.

Thanks for sharing ..


Yes - and even for the experienced to remind them of the order of operations.Cool



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

david.wright-948385
david.wright-948385
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1059 Visits: 963
sknox (2/12/2014)
...This can be alleviated by formatting, e.g:

WHERE
(
(a = b)
OR
(b = c)
)
AND
...


as opposed to

WHERE ((a = b) OR (b = c)) AND ((c = d) OR ((d = e) AND (e = f)))



Exactly. IMHO, this goes for general query layout too.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search