STUFF()
STUFF() is a SQL function in the SQL Server Specific category. SQL Server: deletes a specified length of characters from a string and inserts another string at the start position. The syntax is STUFF(string, start, length, replace_string). It accepts string, start, length, replace_string. It returns modified string. A typical example: SELECT STUFF('Hello World', 7, 5, 'SQL'); -- 'Hello SQL' -- Deletes 5 chars starting at position 7 ('World'), inserts 'SQL' -- Common use: string concatenation for CSV SELECT STUFF(( SELECT ', ' + name FROM employees FOR XML PATH('') ), 1, 2, '') AS name_list; A close relative is OUTPUT Clause, which sQL Server: returns values from DML statements (like PostgreSQL RETURNING). A close relative is FOR XML PATH, which sQL Server: converts query results to XML format. Commonly used for string concatenation hack. A close relative is TRY...CATCH, which sQL Server: structured error handling. Captures runtime errors in the CATCH block.