String Format functionality in SQL

The c# String.Format functionality is extremely helpful. Not only is the code easy to write, but also easy to read.

I’ve found it difficult to write the same code in SQL. Having to concatenate strings with + symbols and be tedious.

Thankfully, there is the standard function FORMATMESSAGE available, which performs a very similar function.

-- RETURNS Hello World, 123
DECLARE @s VARCHAR(50) = 'World';
DECLARE @d INT = 123;
SELECT FORMATMESSAGE('Hello %s, %d', @s, @d)