![]() |
VOOZH | about |
The STUFF() function in SQL Server is a powerful string manipulation tool used to delete a specified length of characters from a string and insert another set of characters at a given starting position. This function becomes particularly useful in scenarios where complex string operations are required such as formatting output, merging data fields or generating custom reports.
In this article, We will learn about SQL Server STUFF() Function in detail and so on.
STUFF() function in SQL Server is used to delete a specified length of characters from a string and then insert another set of characters at a specified starting position.STUFF() Function can play a crucial role in complex queries where string manipulation is needed. Itβs particularly useful when dealing with formatted output or combining data fields in reports. Syntax:
STUFF (source_string, start, length, add_string)Where:
Note: It is not necessary to have the length of the new string and number of characters to be deleted the same.
Example 1:
π Image
Output:
Example 2:
Output:
π Image
Example 3:
Output:
π ImageThe STUFF() function is an essential tool for string manipulation in SQL Server, providing flexibility and control over how strings are modified. Whether you're preparing formatted output or working with complex queries, STUFF() offers a straightforward solution to replace or insert character sequences within strings.