In C#, if I do:
string code = string.format("C{0:000}", 7);
The result will be: C007
Is there a function in SQL Server that does the same thing? Or do I have to create a function myself?
Use FORMATMESSAGE() function.
SELECT FORMATMESSAGE('This is the %s and this is the %s.', 'first variable', 'second variable') AS Result;
https://msdn.microsoft.com/en-us/library/ms186788.aspx
In straight TSQL, there is nothing as powerful as the C# string.format. The CONVERT() function offers some limited formatting, but for anything it can't handle you'd have to write your own function. Google "SQL String functions" to see what tools you have in your SQL arsenal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With