{"id":5692,"date":"2013-05-11T00:00:11","date_gmt":"2013-05-11T00:00:11","guid":{"rendered":"http:\/\/craftydba.com\/?p=5692"},"modified":"2016-04-22T14:43:48","modified_gmt":"2016-04-22T14:43:48","slug":"operator-precedence","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5692","title":{"rendered":"Operator Precedence"},"content":{"rendered":"<p>I am going to bring closure to my series of very short articles or tidbits on Transaction SQL Operators.  An operator is a symbol specifying an action that is performed on one or more expressions. <\/p>\n<p>I will exploring the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190276.aspx\">operator precedence<\/a> today.  In mathematics and computer programming, the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Order_of_operations\">order of operations<\/a> is a set of rules used to clarify which procedures should be performed first in a given mathematical expression.<\/p>\n<p>I do not have enough time in this very short article to go over the eight levels that group and order expression evaluation.  However, I want to go over one example in which parentheses can be used to change the order of evaluation.<\/p>\n<p>The first expression evaluates multiplication first since it is considered a higher level than subtraction.  The second example changes the order by using parentheses.<\/p>\n<p>The example script below explores all three operators.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"operator precedence\">\r\n--\r\n-- Operator Precedence\r\n--\r\n\r\n-- Results in 2\r\nselect x = 2*3-2*2;\r\n\r\n-- Results in 4\r\nselect 2*(3-2)*2 as y;\r\n\r\n<\/pre>\n<p>The output of the above TSQL statements is listed below. <\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\n-- ~ OUTPUT ~\r\nx\r\n-----------\r\n2\r\n\r\ny\r\n-----------\r\n4\r\n\r\n<\/pre>\n<\/p>\n<p>If your Transaction SQL code is not evaluating the programming expression as you would like, consider using parentheses.  Next time I will be talking about <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/hh213226.aspx\">logic functions<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am going to bring closure to my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions. I will exploring the operator precedence today. In mathematics and computer programming, the order of operations is a set of rules used to clarify which procedures should be performed first in a given mathematical expression. I do not have enough time in this very short article to go over the eight levels that group and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5699,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[814],"tags":[31,15,850,28,29],"class_list":["post-5692","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-very-short-articles","tag-database-developer","tag-john-f-miner-iii","tag-operator-precedence","tag-sql-server","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5692"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5692\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/media\/5699"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}