{"id":5221,"date":"2013-04-10T00:00:32","date_gmt":"2013-04-10T00:00:32","guid":{"rendered":"http:\/\/craftydba.com\/?p=5221"},"modified":"2017-10-11T16:18:36","modified_gmt":"2017-10-11T16:18:36","slug":"string-functions-len","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5221","title":{"rendered":"String Functions &#8211; LEN()"},"content":{"rendered":"<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/04\/turquoise-yarn-md.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-5158\" title=\"turquoise-yarn-md\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/04\/turquoise-yarn-md-150x150.png\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><br \/>\nI am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the LEN() function today.<\/p>\n<p>The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190329.aspx\">LEN()<\/a> function takes one string argument as input and returns one integer argument, the size of the input string, as output<\/p>\n<p>The following example determines the title length of a favorite movie of mine.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - len()\">\r\n-- My favorite movie title returns a size of 12\r\nselect len('wizard of oz') as str_size\r\n<\/pre>\n<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nstr_size\r\n-----------\r\n12\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 - len()\">\r\n-- Null returns Null\r\nselect len(NULL) as str_size\r\n<\/span><\/pre>\n<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nstr_size\r\n-----------\r\nNULL\r\n<\/pre>\n<\/p>\n<p>Last but not least, the empty string may return interesting results.  In our case, the length of a empty string is zero.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - len()\">\r\n-- Empty string returns 0\r\nselect len('') as str_size\r\n<\/pre>\n<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nstr_size\r\n-----------\r\n0\r\n<\/pre>\n<\/p>\n<p>Next time, I will be exploring the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms174400.aspx\">LOWER()<\/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 LEN() function today. The LEN() function takes one string argument as input and returns one integer argument, the size of the input string, as output The following example determines the title length of a favorite movie of mine. &#8212; My favorite movie title returns a size of 12 select len(&#8216;wizard of oz&#8217;) as str_size output: str_size &#8212;&#8212;&#8212;&#8211; 12 One thing to always worry about when using TSQL functions&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,819,815,29],"class_list":["post-5221","post","type-post","status-publish","format-standard","hentry","category-very-short-articles","tag-database-developer","tag-john-f-miner-iii","tag-len","tag-string-function","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5221","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=5221"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5221\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}