SQL Server: STUFF Function

This SQL Server tutorial explains how to use the STUFF function in SQL Server (Transact-SQL) with syntax and examples.


In SQL Server (Transact-SQL), the STUFF function deletes a sequence of characters from a source string and then inserts another sequence of characters into the source string, starting at a specified position.


The syntax for the STUFF function in SQL Server (Transact-SQL) is:

STUFF( source_string, start, length, add_string )

Parameters or Arguments

The source string to modify.
The position in the source_string to delete length characters and then insert add_string.
The number of characters to delete from source_string.
The sequence of characters to insert into the source_string at the start position.


Applies To

The STUFF function can be used in the following versions of SQL Server (Transact-SQL):

  • SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005


Let’s look at some SQL Server STUFF function examples and explore how to use the STUFF function in SQL Server (Transact-SQL).

For example:

SELECT STUFF('TechOnTheNet.com', 1, 12, 'CheckYourMath');
Result: 'CheckYourMath.com'

SELECT STUFF('TechOnTheNet.com', 5, 2, '1234');
Result: 'Tech1234TheNet.com'

SELECT STUFF('TechOnTheNet.com', 13, 4, ' is a great site!');
Result: 'TechOnTheNet is a great site!'