FORMATMESSAGE()
FORMATMESSAGE() is a SQL function in the String Functions category. SQL Server: formats a message string using printf-style formatting. Useful for dynamic error messages. The syntax is FORMATMESSAGE('format', arg1, arg2, ...). It accepts see syntax. It returns formatted string. A typical example: SELECT FORMATMESSAGE('Employee %s has salary %d', 'Alice', 75000); -- 'Employee Alice has salary 75000' -- With date: SELECT FORMATMESSAGE('Report generated at %s', CONVERT(VARCHAR, GETDATE(), 120)); -- For RAISERROR: DECLARE @msg NVARCHAR(2048) = FORMATMESSAGE('User %d not found in %s', @id, @table); THROW 50001, @msg, 1; -- PostgreSQL equivalent: -- SELECT FORMAT('Employee %s has salary %s', name, salary::TEXT) FROM employees; -- MySQL: -- SELECT CONCAT('Employee ', name, ' has salary ', salary); A close relative is CONCAT(), which concatenates two or more strings into one string. Returns NULL if any argument is NULL. A close relative is SUBSTRING(), which extracts characters from a string starting at position `start` for `length` characters.