Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Logic Precedence Expand / Collapse
Author
Message
Posted Wednesday, February 12, 2014 2:20 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Today @ 3:05 AM
Points: 626, Visits: 1,137
very good question for the beginners to understand what OR , AND does.

Thanks for sharing ..
Post #1540591
Posted Wednesday, February 12, 2014 3:31 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 9:14 AM
Points: 982, Visits: 750
Always add brackets when mixing operators. Even if you know the rules, brackets make a calculation less prone to misunderstanding.
Post #1540604
Posted Wednesday, February 12, 2014 3:45 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Sunday, July 13, 2014 1:06 AM
Points: 971, Visits: 2,551
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
Post #1540607
Posted Wednesday, February 12, 2014 4:11 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 5:47 AM
Points: 3,855, Visits: 4,994
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”
Post #1540621
Posted Wednesday, February 12, 2014 5:03 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, July 18, 2014 2:05 PM
Points: 3,943, Visits: 2,957
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
Post #1540654
Posted Wednesday, February 12, 2014 6:44 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 5:50 AM
Points: 1,712, Visits: 6,239
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?
Post #1540700
Posted Wednesday, February 12, 2014 6:51 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 7:13 AM
Points: 2,381, Visits: 176
WhooHoo I got it.
Post #1540703
Posted Wednesday, February 12, 2014 7:29 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 7:26 AM
Points: 1,293, Visits: 1,646
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...
Post #1540725
Posted Wednesday, February 12, 2014 7:46 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 6:40 AM
Points: 21,209, Visits: 14,890
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.




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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1540733
Posted Wednesday, February 12, 2014 7:55 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 9:14 AM
Points: 982, Visits: 750
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.
Post #1540744
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse