SQL Server STUFF() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server STUFF() Function

❮ SQL Server Functions

Example

Delete 3 characters from a string and then insert another sequence of characters, starting in position 1:

SELECT STUFF('SQL Tutorial', 1, 3, 'HTML');
Try it Yourself »

Definition and Usage

The STUFF() function deletes a sequence of characters from a string and then inserts another sequence of characters into the string, starting at a specified position.

Tip: See also the REPLACE() function.

Syntax

STUFF(string1, start, length, add_string)

Parameter Values

Parameter Description
string1 Required. The source string to modify
start Required. The position in string1 to start delete length characters, and then insert add_string
length Required. The number of characters to delete from string1
add_string Required. The sequence of characters to insert into string1 at the start position

Technical Details

Works in: SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

More Examples

Example

Delete 1 character from a string and then insert another sequence of characters, starting in position 13:

SELECT STUFF('SQL Tutorial!', 13, 1, ' is fun!');
Try it Yourself »

❮ SQL Server Functions