Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

STUFF

Example

Remove 3 characters from the beginning of a string and replace them with “HTML”.

SELECT STUFF(‘SQL Tutorial’13‘HTML’);

Definition and Usage

The STUFF() function in SQL deletes a specified length of characters from a string and replaces them with another string at a specified starting position.

Tip: Consider using the REPLACE() function as well.

Syntax

STUFF(stringstartlengthnew_string)

Parameter Values

Parameter

Description

string

Required: Specifies the string that will be altered.

start

Required: Specifies the starting position within the string from where characters will be deleted.

length

Required: Specifies the number of characters to remove from the string.

new_string

Required: Specifies the new string that will replace the deleted characters at the specified start position in the original string.

Technical Details

Works in:

 SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse

More Examples

Example

Remove 1 character from position 13 of a string and replace it with ” is fun!”.

SELECT STUFF(‘SQL Tutorial!’131‘ is fun!’);