{"id":5679,"date":"2013-05-10T00:00:15","date_gmt":"2013-05-10T00:00:15","guid":{"rendered":"http:\/\/craftydba.com\/?p=5679"},"modified":"2016-04-22T14:48:52","modified_gmt":"2016-04-22T14:48:52","slug":"unary-operators","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5679","title":{"rendered":"Unary Operators"},"content":{"rendered":"<p>I am going to stick to writing 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\/ms188400.aspx\">Unary Operators<\/a> today.  In mathematics, a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Unary_operation\">unary<\/a> operation is an operation with only one operand.<\/p>\n<p>Microsoft Transaction SQL has three unary operators:  <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms174362.aspx\">positive<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms189480.aspx\">negative<\/a>, and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms173468.aspx\">bitwise not<\/a>. <\/p>\n<p>I have personally used the bitwise operators when dealing with data from car manufacturing devices that use application specific integrated circuits (ASIC).  Since the memory space of these little devices are small, bits are used to store information about a condition. <\/p>\n<p>The example script below explores all three operators.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"unary operators\">\r\n--\r\n--  Unary operators \r\n--\r\n\r\n-- negative\r\ndeclare @x int = 5;\r\nselect -@x as negative;\r\n\r\n-- positive\r\ndeclare @y int = 5;\r\nselect +@y as positive;\r\n\r\n-- ones complement\r\ndeclare @z int = 0x7F;\r\nselect ~ @z;\r\n\r\n<\/pre>\n<p>\nThe output of the above TSQL statements is listed below.\n<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\n-- ~ OUTPUT ~\r\nnegative\r\n-----------\r\n-5\r\n\r\npositive\r\n-----------\r\n5\r\n\r\nones_complement\r\n---------------\r\n-128\r\n\r\n<\/pre>\n<\/p>\n<p>I find the positive unary operator kinda-of useless.  It will not take a negative number and make it positive.  By default, a non-negative number is positive.  I think is part of the language for mathematical completeness.<\/p>\n<p>To complete my exploration of operators, I will be talking about <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190276.aspx\">operator precedence<\/a> next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am going to stick to writing 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 Unary Operators today. In mathematics, a unary operation is an operation with only one operand. Microsoft Transaction SQL has three unary operators: positive, negative, and bitwise not. I have personally used the bitwise operators when dealing with data from car manufacturing devices that use application specific integrated circuits (ASIC). Since the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5689,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[814],"tags":[31,15,28,29,849],"class_list":["post-5679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-very-short-articles","tag-database-developer","tag-john-f-miner-iii","tag-sql-server","tag-tsql","tag-unary-operator"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5679","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=5679"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5679\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/media\/5689"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}