STUFF()

The STUFF function inserts a string into another string.

Signature

STUFF ( character_expression , start , length , replace_with_expression )

Parameters

  • character_expression — An expression of character data. *character_expression* can be a constant, variable, or column of either character or binary data.
  • start — An integer value that specifies the location to start deletion and insertion. If *start* is negative or zero, a null string is returned. If *start* is longer than the first *character_expression*, a null string is returned. *start* can be of type bigint.
  • length — An integer that specifies the number of characters to delete. If *length* is negative, a null string is returned. If *length* is longer than the first *character_expression*, deletion occurs up to the last character in the last *character_expression*. If *length* is zero, insertion occurs at the start location, and no characters are deleted. *length* can be of type bigint.
  • replace_with_expression — An expression of character data. *replace_with_expression* can be a constant, variable, or column of either character or binary data. This expression replaces *length* characters of *character_expression* beginning at *start*. Providing `NULL` as the *replace_with_expression*, removes characters without inserting anything.

Examples

SELECT STUFF('keyboard', 4, 5, '-') AS stuffed;
stuffed
-------
key-

Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.

Available on

  • SQL Server 2017 and later
  • Azure SQL Database
  • Azure SQL Managed Instance
  • Azure Synapse Analytics
  • Analytics Platform System (PDW)
  • Microsoft Fabric warehouse
  • Fabric SQL database

Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.