{"id":3101,"date":"2014-11-29T03:20:09","date_gmt":"2014-11-28T21:50:09","guid":{"rendered":"http:\/\/sqlhints.com\/?p=3101"},"modified":"2015-07-18T02:24:24","modified_gmt":"2015-07-17T20:54:24","slug":"stuff-function-in-sql-server","status":"publish","type":"post","link":"https:\/\/sqlhints.com\/2014\/11\/29\/stuff-function-in-sql-server\/","title":{"rendered":"STUFF Function in Sql Server"},"content":{"rendered":"<p style=\"text-align: justify;\">This article explains the string function STUFF with extensive list of examples.<\/p>\n<h3>Description:<\/h3>\n<p style=\"text-align: justify;\">STUFF function adds the <em>Addon_String <\/em>into the <em>Source_string <\/em>at the specified <em>Start <\/em>position in the <em>Source_String<\/em>. Before adding the <em>AddOn_String <\/em>into the <em>Source_string<\/em>, it deletes the number of characters specified by the <em>Length <\/em>parameter from the <em>Start <\/em>position in the <em>Source_string<\/em>.<\/p>\n<h3>Syntax:<\/h3>\n<p>STUFF(<em>Source_String<\/em>, <em>Start<\/em>, <em>Length<\/em>, <em>AddOn_String<\/em>)<\/p>\n<h3>Examples:<\/h3>\n<h5>Example 1:<\/h5>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;SqlServer.com&#039;, 4, 6, &#039;Hints&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSqlHints.com<\/p>\n<h5>Example 2:<\/h5>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;Sql.com&#039;, 4, 0, &#039;Hints&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSqlHints.com<\/p>\n<h5>Example 3:<\/h5>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;Hints.com&#039;, 1, 0, &#039;Sql&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSqlHints.com<\/p>\n<h5>Example 4:<\/h5>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;#SqlHints.com&#039;, 1, 1, &#039;&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSqlHints.com<\/p>\n<h5>Example 5:<\/h5>\n<p>If <em>Start<\/em> position is larger than length of the first string, a null string is returned<\/p>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;SqlHints&#039;, 9, 0, &#039;.com&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nNULL<\/p>\n<h5>Example 6:<\/h5>\n<p>If <em>Start<\/em> position is 0, a null value is returned.<\/p>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;Hints.com&#039;, 0, 0, &#039;Sql&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nNULL<\/p>\n<h5>Example 7:<\/h5>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;SqlHints#&#039;, 9, 1, &#039;.com&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSqlHints.com<\/p>\n<h5>Example 8:<\/h5>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;SqlHints#&#039;, 9, 8, &#039;.com&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSqlHints.com<\/p>\n<h5>Example 9:<\/h5>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;SqlHints#&#039;, 9, 20, &#039;.com&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSqlHints.com<\/p>\n<h5>Example 10:<\/h5>\n<p>If <em>Length<\/em> is negative, a null string is returned<\/p>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;Sql.com&#039;, 4, -1, &#039;Hints&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nNULL<\/p>\n<h5>Example 11:<\/h5>\n<p>If <em>Start<\/em> position is negative, a null string is returned<\/p>\n<pre class=\"brush: sql; gutter: false\">SELECT STUFF(&#039;Hints.com&#039;, -1, 0, &#039;Sql&#039;) &#039;STUFF RESULT&#039;<\/pre>\n<p><strong>RESULT:<\/strong><br \/>\nSTUFF RESULT<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nNULL<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article explains the string function STUFF with extensive list of examples. Description: STUFF function adds the Addon_String into the Source_string at the specified Start position in the Source_String. Before adding the AddOn_String into the Source_string, it deletes the number of characters specified by the Length parameter from the Start position in the Source_string. Syntax: &hellip; <a href=\"https:\/\/sqlhints.com\/2014\/11\/29\/stuff-function-in-sql-server\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">STUFF Function in Sql Server<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[447,448,321,986,692,691,58,442,445,443,444,446],"class_list":["post-3101","post","type-post","status-publish","format-standard","hentry","category-sql-server","tag-add-string-into-another-string","tag-adding-string-into-another-string-in-sql-server","tag-sql","tag-sql-server","tag-sql-stuff","tag-sql-stuff-function","tag-string-functions","tag-stuff","tag-stuff-function","tag-stuff-sql","tag-stuff-sql-server","tag-stuff-sql-string-function"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3xNAz-O1","_links":{"self":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/posts\/3101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/comments?post=3101"}],"version-history":[{"count":12,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/posts\/3101\/revisions"}],"predecessor-version":[{"id":3113,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/posts\/3101\/revisions\/3113"}],"wp:attachment":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/media?parent=3101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/categories?post=3101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/tags?post=3101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}