{"id":5318,"date":"2013-04-18T00:00:56","date_gmt":"2013-04-18T00:00:56","guid":{"rendered":"http:\/\/craftydba.com\/?p=5318"},"modified":"2017-10-08T16:29:41","modified_gmt":"2017-10-08T16:29:41","slug":"5318","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5318","title":{"rendered":"String Functions &#8211; REVERSE()"},"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 REVERSE() function today.<\/p>\n<p>The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms180040.aspx\">REVERSE()<\/a> function takes a source string as input and returns each character in the reverse order as output.  Therefore, the last character input string is now the first character in the output string.  And the first character in the input string is last character in the output string.<\/p>\n<p>Let&#8217;s have some fun by using <a href=\"http:\/\/en.wikipedia.org\/wiki\/Palindrome\">palidromes<\/a> in the next example.  The example below has two words that become other words when reverse.  This is usually not the case.  Most of the time, a reversed word is gibberish.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - reverse()\">\r\n-- Palindromes 1\r\nselect 'stressed' as forward, reverse('stressed') as backward\r\n\r\n-- Palindromes 2\r\nselect 'star' as forward, reverse('star') as backward\r\n<\/pre>\n<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nforward  backward\r\n-------- --------\r\nstressed desserts\r\n\r\nforward backward\r\n------- --------\r\nstar    rats\r\n<\/pre>\n<\/p>\n<p>One thing to always worry about when using TSQL functions is how will it react with a EMPTY strings or NULL values?  Both empty strings and NULL values as input return themselves as output.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - reverse()\">\r\n-- Empty string returns empty string\r\nselect reverse('') as str_word\r\n\r\n-- Null returns Null\r\nselect reverse(NULL) as str_word\r\n<\/pre>\n<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nstr_word\r\n--------\r\n\r\nstr_word\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\/ms177532.aspx\">RIGHT()<\/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 REVERSE() function today. The REVERSE() function takes a source string as input and returns each character in the reverse order as output. Therefore, the last character input string is now the first character in the output string. And the first character in the input string is last character in the output string. Let&#8217;s have some fun by using palidromes in the next example. The example below has two&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,825,815,29],"class_list":["post-5318","post","type-post","status-publish","format-standard","hentry","category-very-short-articles","tag-database-developer","tag-john-f-miner-iii","tag-reverse","tag-string-function","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5318","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=5318"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5318\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}