FORMATMESSAGE (SQL equivalent to String.Format)

Supported data types:

d or i Signed integer
o Unsigned octal
s String
u Unsigned integer
x or X Unsigned hexadecimal

Here's a handy one-liner, copy into your code and edit. FORMATMESSAGE does not support NUMERIC datatypes, so we use FORMAT to convert NUMERIC to VARCHAR

PRINT FORMATMESSAGE('Test numeric: %s, test string: %s ', FORMAT(667.20000,'#.##'), 'string value')

 

SELECT FORMATMESSAGE('Signed int %i, %d %i, %d, %+i, %+d, %+i, %+d', 5, -5, 50, -50, -11, -11, 11, 11); 
SELECT FORMATMESSAGE('Signed int with leading zero %020i', 5); 
SELECT FORMATMESSAGE('Signed int with leading zero 0 %020i', -55); 
SELECT FORMATMESSAGE('Unsigned int %u, %u', 50, -50); 
SELECT FORMATMESSAGE('Unsigned octal %o, %o', 50, -50); 
SELECT FORMATMESSAGE('Unsigned hexadecimal %x, %X, %X, %X, %x', 11, 11, -11, 50, -50); 
SELECT FORMATMESSAGE('Unsigned octal with prefix: %#o, %#o', 50, -50); 
SELECT FORMATMESSAGE('Unsigned hexadecimal with prefix: %#x, %#X, %#X, %X, %x', 11, 11, -11, 50, -50); 
SELECT FORMATMESSAGE('Hello %s!', 'TEST'); 
SELECT FORMATMESSAGE('Hello %20s!', 'TEST'); 
SELECT FORMATMESSAGE('Hello %-20s!', 'TEST'); 
SELECT FORMATMESSAGE('Hello %20s!', 'TEST');

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences