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 :
- string: the original string you want to change.
- start: position in the string to start deleting some characters
- length: the number of characters to delete from the string.
- new_string: string of characters to insert into the string at the start position.
Note :
- See also the REPLACE function for selecting and replacing strings.
- 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
You should read it
May be interested
- UPPER function in SQL Serverthe 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 Serverthe 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 Serverthis 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 Serverthe 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 Serverthe ceiling function in sql server returns the smallest integer value greater than or equal to the transmitted numeric expression.
- FLOOR function in SQL Serverthe floor function in sql server returns the largest integer value but less than or equal to the transmitted numeric expression.