{"id":5448,"date":"2013-05-02T00:00:45","date_gmt":"2013-05-02T00:00:45","guid":{"rendered":"http:\/\/craftydba.com\/?p=5448"},"modified":"2017-10-08T16:01:36","modified_gmt":"2017-10-08T16:01:36","slug":"assignment-operator","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5448","title":{"rendered":"Assignment Operator"},"content":{"rendered":"<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/05\/mathematics-one.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/05\/mathematics-one.jpg\" alt=\"\" title=\"mathematics-one\" width=\"550\" height=\"384\" class=\"aligncenter size-full wp-image-5459\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/05\/mathematics-one.jpg 550w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/05\/mathematics-one-300x209.jpg 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><\/p>\n<p>I am going to continue the 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\/ms188343.aspx\">Assignment Operator<\/a> today.  This equality symbol  <span style=\"color: #DD0000;\">=<\/span> in mathematics. <\/p>\n<p>There are two ways in which the assignment operator can be used:  <span style=\"color: #DD0000;\">alias<\/span> &#8211; associating a column heading with a expression or <span style=\"color: #DD0000;\">storage<\/span> &#8211; placing the results of a expression into a variable.<\/p>\n<p>The TSQL example below compares the assignment operator against old and new ANSI standards for aliasing.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"ansi standard - assignment operators\">\r\n--\r\n--  Assignment operator - usage 1\r\n--\r\n\r\n-- Assignment same as alias\r\nselect x = 2 * 3;\r\n\r\n-- Old school alias\r\nselect 2 * 3 y;\r\n\r\n-- New school alias\r\nselect 2 * 3 as z;\r\n<\/pre>\n<\/p>\n<p>The output of each calculation is listed below.<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nx\r\n-----------\r\n6\r\n\r\ny\r\n-----------\r\n6\r\n\r\nz\r\n-----------\r\n6\r\n<\/pre>\n<\/p>\n<p>The TSQL example below is a good example of using the assignment operator to store the results of a expression into a variable.  It creates a temporary table, declares a local variable and sums up the numbers in the temporary table.  <\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"ansi standard - assignment operators\">\r\n--\r\n--  Assignment operator - usage 2\r\n--\r\n\r\n-- Create sample table\r\ndrop table #numbers;\r\ncreate table #numbers (n int);\r\n\r\n-- Add data 2 table\r\ninsert into #numbers values\r\n  (1), (2), (3), (4), (5);\r\nselect * from #numbers;\r\n\r\n-- Allocate local variable\r\ndeclare @t int = 0;\r\n\r\n-- Sum column in table\r\nselect @t = @t + n from #numbers;\r\nselect @t as total;\r\n<\/pre>\n<\/p>\n<p>The output of the summation is listed below.<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\ntotal\r\n-----------\r\n15\r\n<\/pre>\n<\/p>\n<p>Next time, I will be exploring the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms176122.aspx\">Bitwise Operators<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am going to continue the 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 Assignment Operator today. This equality symbol = in mathematics. There are two ways in which the assignment operator can be used: alias &#8211; associating a column heading with a expression or storage &#8211; placing the results of a expression into a variable. The TSQL example below compares the assignment operator against old and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[814],"tags":[834,31,15,29],"class_list":["post-5448","post","type-post","status-publish","format-standard","hentry","category-very-short-articles","tag-assignment-operator","tag-database-developer","tag-john-f-miner-iii","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5448","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=5448"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5448\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}