xp_sprintf Extended Stored Procedure

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]...

where

@string OUTPUT
Is a varchar OUTPUT parameter that will return the result string.
format
Is a format character string similar to that supported by the C-language sprintf. Currently, only the '%s' format argument is supported.
argument
Is a character string that represents the value of the corresponding format argument. As many as 50 arguments can be specified.

Example

    Sending an INSERT

This example uses the @string parameter to send an INSERT statement. The actual value of @string will contain 'INSERT table1 VALUES(1, 2).'

DECLARE @string varchar (255)
EXEC xp_sprintf @string OUTPUT, 'INSERT INTO %s VALUES (%s, %s)', 'table1', '1', '2'

Permission

Execute permission defaults to the public group.

See Also

xp_sscanf