STUFF function in SQL Server

The article will explore and show you how to use the STUFF function to insert a string into another string in SQL Server.

Describe

STUFF function in SQL Server is used to insert a string into another string, the result returned is a new string after canceling some existing characters and adding another substring at the canceled location.

Syntax

To use STUFF function in SQL Server, we use the following syntax:

 STUFF(string, start, length, new_string) 

Parameters :

  1. string: the original string you want to change.
  2. start: position in the string to start deleting some characters
  3. length: the number of characters to delete from the string.
  4. new_string: string of characters to insert into the string at the start position.

Note :

  1. See also the REPLACE function for selecting and replacing strings.
  2. STUFF function can be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.

For example

See and explore some examples of STUFF functions in SQL Server.

 SELECT STUFF('TipsMake.com', 1, 11, 'Meta'); 
Result: 'Meta.com'

SELECT STUFF('QuanTriMang.com', 5, 3, '1234');
Result: 'Quan1234Mang.com'

SELECT STUFF('QuanTriMang.com', 12, 4, ' la website thong tin dien tu');
Result: ' QuanTriMang la website thong tin dien tu'

Previous lesson: STR function in SQL Server

Next article: SUBSTRING function in SQL Server

4 ★ | 1 Vote

May be interested

  • UPPER function in SQL ServerPhoto of UPPER function in SQL Server
    the article will explore and show you how to use upper function in sql server to convert letters in a specified string to uppercase.
  • SUBSTRING function in SQL ServerPhoto of SUBSTRING function in SQL Server
    the article will explore and guide you how to use the substring function in sql server to extract a substring from a specified string.
  • ABS function in SQL ServerPhoto of ABS function in SQL Server
    this article will show you in detail how to use the abs () handling function in sql server with specific syntax and examples to better visualize and capture functions.
  • AVG function in SQL ServerPhoto of AVG function in SQL Server
    the avg function in sql server returns the average value of an expression or average value according to the specified column of the selected row.
  • CEILING function in SQL ServerPhoto of CEILING function in SQL Server
    the ceiling function in sql server returns the smallest integer value greater than or equal to the transmitted numeric expression.
  • FLOOR function in SQL ServerPhoto of FLOOR function in SQL Server
    the floor function in sql server returns the largest integer value but less than or equal to the transmitted numeric expression.