## Logic Precedence

 Author Message twin.devil SSChampion Group: General Forum Members Points: 12250 Visits: 2897 very good question for the beginners to understand what OR , AND does.Thanks for sharing .. david.wright-948385 SSCrazy Group: General Forum Members Points: 2316 Visits: 995 Always add brackets when mixing operators. Even if you know the rules, brackets make a calculation less prone to misunderstanding. kupy Ten Centuries Group: General Forum Members Points: 1254 Visits: 2685 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 SSC-Dedicated Group: General Forum Members Points: 35280 Visits: 7698 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 SSC Guru Group: General Forum Members Points: 156411 Visits: 11650 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 PersonifiedString Splitting with True PerformanceBest practices on how to ask questions Toreador SSCertifiable Group: General Forum Members Points: 5926 Visits: 8278 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 SSCertifiable Group: General Forum Members Points: 6919 Visits: 3158 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 SSC Guru Group: General Forum Members Points: 143753 Visits: 18651 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, MVPSQL RNNRPosting Performance Based Questions - Gail ShawLearn Extended Events david.wright-948385 SSCrazy Group: General Forum Members Points: 2316 Visits: 995 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.