{"id":5202,"date":"2013-04-06T00:00:36","date_gmt":"2013-04-06T00:00:36","guid":{"rendered":"http:\/\/craftydba.com\/?p=5202"},"modified":"2017-10-11T16:25:28","modified_gmt":"2017-10-11T16:25:28","slug":"string-function-concat","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5202","title":{"rendered":"String Function  &#8211; CONCAT()"},"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 CONCAT() function today.<\/p>\n<p>The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/hh231515.aspx\">CONCAT()<\/a> function takes two or more string arguments and combines them into one string.  Any arguements that are not strings are converted to a string.  All NULL values are converted to the empty string &#8216; &#8216;.<\/p>\n<p>The following example takes seven input arguements of various data types and returns one string output.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - concat()\">\r\n-- Local variable\r\ndeclare @var_tmp varchar(32);\r\n\r\n-- Combine strings into one\r\nselect @var_tmp = concat('Fi', 've', ' plus', NULL, ' four equals nine (', 9, ').');\r\n\r\n-- Show the resulting string\r\nselect @var_tmp as one_string;\r\n\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\none_string\r\n--------------------------------\r\nFive plus four equals nine (9).\r\n\r\n<\/pre>\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<p>In the example below, two NULL values equal one empty string.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - concat()\">\r\n-- Local variable\r\ndeclare @var_tmp varchar(32);\r\n\r\n-- Combine NULLS into one variable\r\nselect @var_tmp = concat(NULL, NULL);\r\n\r\n-- Show the resulting string\r\nselect @var_tmp as one_string;\r\n\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\none_string\r\n--------------------------------\r\n<\/pre>\n<\/p>\n<p>Next time, I will be exploring the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms188753.aspx\">DIFFERENCE()<\/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 CONCAT() function today. The CONCAT() function takes two or more string arguments and combines them into one string. Any arguements that are not strings are converted to a string. All NULL values are converted to the empty string &#8216; &#8216;. The following example takes seven input arguements of various data types and returns one string output. &#8212; Local variable declare @var_tmp varchar(32); &#8212; Combine strings into one select&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":[817,31,15,815,29],"class_list":["post-5202","post","type-post","status-publish","format-standard","hentry","category-very-short-articles","tag-concat","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\/5202","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=5202"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5202\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}