{"id":5264,"date":"2013-04-13T00:00:25","date_gmt":"2013-04-13T00:00:25","guid":{"rendered":"http:\/\/craftydba.com\/?p=5264"},"modified":"2017-10-11T16:13:39","modified_gmt":"2017-10-11T16:13:39","slug":"string-functions-nchar","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5264","title":{"rendered":"String Functions &#8211; NCHAR()"},"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 continue my series of very short articles or tidbits on Transaction SQL string functions.  I will exploring the NCHAR() function today.<\/p>\n<p>The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms182673.aspx\">NCHAR()<\/a> function takes an integer value, UNICODE value from 0 to 65535 and returns a single UNICODE character string.<\/p>\n<p>The following example returns the character &#8216;0&#8217; given the UNICODE value of 48.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - nchar()\">\r\n-- ASCII\/UNICODE value for zero\r\ndeclare @var_tmp int = 48;\r\n\r\n-- Return the single character, zero\r\nselect nchar(@var_tmp) as single_nchar;\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput:\r\n\r\nsingle_nchar\r\n-----------\r\n0\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 values? <\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - nchar()\">\r\n-- UNKNOWN value returns NULL\r\nselect nchar(NULL) as single_nchar;\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput:\r\n\r\nsingle_nchar\r\n-----------\r\nNULL\r\n<\/pre>\n<\/p>\n<p>Another thing to test is how the function will work with values out of range?<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - nchar()\">\r\n-- Out of range value, lower range, returns NULL\r\nselect nchar(0-1) as single_nchar;\r\n\r\n-- Out of range value, upper range, returns NULL\r\nselect nchar(65535+1) as single_nchar;\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput:\r\n\r\nsingle_nchar\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\/ms188395.aspx\">PATINDEX()<\/a> function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the NCHAR() function today. The NCHAR() function takes an integer value, UNICODE value from 0 to 65535 and returns a single UNICODE character string. The following example returns the character &#8216;0&#8217; given the UNICODE value of 48. &#8212; ASCII\/UNICODE value for zero declare @var_tmp int = 48; &#8212; Return the single character, zero select nchar(@var_tmp) as single_nchar; output: single_nchar &#8212;&#8212;&#8212;&#8211; 0 One thing to always worry about when using&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":[31,15,538,815,29],"class_list":["post-5264","post","type-post","status-publish","format-standard","hentry","category-very-short-articles","tag-database-developer","tag-john-f-miner-iii","tag-nchar","tag-string-function","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5264","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=5264"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5264\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}