Simplified Order Of Operations

Kevin Feasel

2016-07-22

T-SQL

Michael J. Swart looks at how SQL Server implements order of operations:

I have a book on my shelf called Practical C Programming published by O’Reilly (the cow book) by Steve Oualline. I still love it today because although I don’t code in C any longer, the book remains a great example of good technical writing.

That book has some relevance to SQL today. Instead of memorizing the full list of operators and their precedence, Steve gives a practical subset:

    1. * (Multiply), / (Division)
    2. + (Add), – (Subtract)

Put parentheses around everything else.

Parentheses, even when unnecessary, are usually a good idea.  They help the reader understand what was going through your mind at the time.

Related Posts

Your Reminder Not To MERGE

Kevin Wilkie points out the numerous problems with the MERGE operator: Now, when I last posted, I’m sure you thought I was done talking about the MERGE statement. You are so wrong, compadre! One more post is absolutely needed! There are a few issues with the MERGE statement. Well, as of this writing, there are 361 possible issues according […]

Read More

CROSS APPLY Replacing REPLACE

Bert Wagner shows off a good use of the APPLY operator: Here we only have 4 nested REPLACE functions. My shameful record is 29. I’m not proud of it, but sometimes it’s the only way to get things done. Not only are these nested REPLACE() functions difficult to write, but they are difficult to read […]

Read More

Categories

July 2016
MTWTFSS
« Jun Aug »
 123
45678910
11121314151617
18192021222324
25262728293031