SQL Server | STUFF() Function Last Updated : 20 Aug, 2024 Comments Improve Suggest changes Like Article Like Report 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.SQL Server STUFF() FunctionThe 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:source_string: Original string to be modified. start: The starting index from where the given length of characters will be deleted and new sequence of characters will be inserted.length: The numbers of characters to be deleted from the starting index in the original string. add_string: The new set of characters (string) to be inserted in place of deleted characters from the starting index.Note: It is not necessary to have the length of the new string and number of characters to be deleted the same. Examples of SQL Server STUFF() FunctionExample 1: Output: Example 2: Output: Example 3: Output: ConclusionThe 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. Comment More infoAdvertise with us Next Article SQL Server | STUFF() Function S Sam007 Follow Improve Article Tags : SQL Databases SQL-Server Similar Reads SQL Server TRIM() Function The SQL Server TRIM() function omits the space character or additional stated characters from the beginning or the end of a specified string. TRIM in SQL ServerThe TRIM function in SQL Server is used to remove leading and trailing spaces from a string. Itâs particularly useful for manipulating and c 2 min read SQL Server SUBSTRING() Function The SQL Server SUBSTRING function extracts a substring from a string, starting at a specified position and with an optional length. The SUBSTRING function also works in Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse. SyntaxThe SQL SUBSTRING function syntax is: SUBSTRING(in 3 min read SQL Server SPACE() function The SQL Server SPACE() function is a handy tool for generating a string of space characters. It is particularly useful for formatting and padding data within SQL queries. By specifying the number of spaces, users can ensure consistent spacing in output results, which can be critical for aligning tex 3 min read LOG() Function in SQL Server The LOG() function returns the logarithm of a specified number or the logarithm of the number to the specified base. Syntax : LOG(number, base) Parameter : LOG() function accepts two-parameters as mentioned above and described below. number - This parameter hold a number which is greater than 0. bas 1 min read SIGN() Function in SQL Server In SQL Server, the SIGN() function is a mathematical function used to determine the sign of a given numeric expression. This function is particularly useful when we want to evaluate whether a number is positive, negative or zero. In this article, We will learn about SIGN() Function in SQL Server in 3 min read Like