{"id":5151,"date":"2013-04-03T00:00:26","date_gmt":"2013-04-03T00:00:26","guid":{"rendered":"http:\/\/craftydba.com\/?p=5151"},"modified":"2017-10-11T16:30:00","modified_gmt":"2017-10-11T16:30:00","slug":"string-functions-ascii","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5151","title":{"rendered":"String Function &#8211; ASCII()"},"content":{"rendered":"<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/04\/turquoise-yarn-md.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/04\/turquoise-yarn-md-150x150.png\" alt=\"\" title=\"turquoise-yarn-md\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-5158\" \/><\/a><br \/>\nI am going to write a series of very short articles or tidbits on Transaction SQL (TSQL) functions.  I will start exploring the string functions today in alphabetical order.<\/p>\n<p>Before the invention of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Unicode\">UNICODE<\/a>,  we were able to express only 128 different characters with 7 bit <a href=\"http:\/\/en.wikipedia.org\/wiki\/ASCII\">ASCII<\/a> code.  <\/p>\n<p>Transaction SQL (TSQL) still supports the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms177545.aspx\">ASCII()<\/a> function that takes a CHAR or VARCHAR datatype as input and returns a INT datatype as output.<\/p>\n<p>The following example returns the ASCII code for a space which is a value of 32.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - ascii()\">\r\n-- A simple space\r\ndeclare @var_tmp char = ' ';\r\n\r\n-- Return ascii #\r\nselect ascii(@var_tmp) as ascii_code;\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput:\r\n\r\nascii_code\r\n-----------\r\n32\r\n<\/pre>\n<\/p>\n<p>One thing to always worry about when using TSQL functions is how will it react with a UNKNOWN or NULL value?<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - ascii()\">\r\n-- A unknown value\r\ndeclare @var_tmp char = NULL;\r\n\r\n-- Return ascii #\r\nselect ascii(@var_tmp) as ascii_code;\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput:\r\n\r\nascii_code\r\n-----------\r\nNULL\r\n<\/pre>\n<\/p>\n<p>Next time, I will be exploring the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms187323.aspx\">CHAR()<\/a> function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am going to write a series of very short articles or tidbits on Transaction SQL (TSQL) functions. I will start exploring the string functions today in alphabetical order. Before the invention of UNICODE, we were able to express only 128 different characters with 7 bit ASCII code. Transaction SQL (TSQL) still supports the ASCII() function that takes a CHAR or VARCHAR datatype as input and returns a INT datatype as output. The following example returns the ASCII code for a space which is a value of 32. &#8212; A&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":[816,31,15,815,29],"class_list":["post-5151","post","type-post","status-publish","format-standard","hentry","category-very-short-articles","tag-ascii","tag-database-developer","tag-john-f-miner-iii","tag-string-function","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5151","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=5151"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5151\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}