xp_sprintf
Formats and stores a series of characters and values in the string output parameter. Each format argument is replaced with the corresponding argument.
Syntax
xp_sprintf {string OUTPUT, format}
[, argument [,...n]]
Arguments
string
Is a varchar variable that receives the output.
OUTPUT
When specified, places the value of the variable in the output parameter.
format
Is a format character string with placeholders for argument values, similar to that supported by the C-language sprintf function. Currently, only the %s format argument is supported.
argument
Is a character string representing the value of the corresponding format argument.
n
Is a placeholder indicating that a maximum of 50 arguments can be specified.
Return Code Values
0 (success) or 1 (failure)
Result Sets
xp_sprintf returns this message:
The command(s) completed successfully.
Permissions
Execute permissions default to the public role.
Examples
This example uses parameter to create an INSERT statement.
DECLARE @ret_string varchar (255)
EXEC xp_sprintf @ret_string OUTPUT, 'INSERT INTO %s VALUES (%s, %s)', 'table1', '1', '2'
PRINT @ret_string
Here is the result set:
INSERT INTO table1 VALUES (1, 2)
See Also
System Stored Procedures (General Extended Procedures)