SQL Server 中的函数与 C# 中的 string.format 类似

Cli*_*chi 4 c# sql t-sql sql-server sql-server-2005

在 C# 中,如果我这样做:

string code = string.format("C{0:000}", 7);
Run Code Online (Sandbox Code Playgroud)

结果将是:C007

SQL Server中有没有一个函数可以做同样的事情?或者我必须自己创建一个函数?

has*_*trb 5

使用 FORMATMESSAGE() 函数。

SELECT FORMATMESSAGE('This is the %s and this is the %s.', 'first variable', 'second variable') AS Result; 
Run Code Online (Sandbox Code Playgroud)

https://msdn.microsoft.com/en-us/library/ms186788.aspx