| title | xp_sscanf (Transact-SQL) | ||
|---|---|---|---|
| description | Reads data from the string into the argument locations specified by each format argument. | ||
| author | markingmyname | ||
| ms.author | maghan | ||
| ms.reviewer | randolphwest | ||
| ms.date | 06/23/2025 | ||
| ms.service | sql | ||
| ms.subservice | system-objects | ||
| ms.topic | reference | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
[!INCLUDE SQL Server]
Reads data from the string into the argument locations specified by each format argument.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
xp_sscanf { 'string' OUTPUT , 'format' } [ , 'argument' [ , ...n ] ]
[!INCLUDE extended-stored-procedures]
The character string to read the argument values from.
When OUTPUT is specified, string puts the value of argument in the output parameter.
A formatted character string, similar to the values supported by the C-language sscanf function. Currently, only the %s format argument is supported.
A varchar variable set to the value of the corresponding format argument.
A placeholder that indicates that a maximum of 50 arguments can be specified.
0 (success) or 1 (failure).
xp_sscanf returns the following message:
Command(s) completed successfully.
Requires membership in the public role.
The following example uses xp_sscanf to extract two values from a source string based on their positions in the format of the source string.
DECLARE @filename AS VARCHAR (20), @message AS VARCHAR (20);
EXECUTE xp_sscanf 'sync -b -fproducts10.tmp -rrandom', 'sync -b -f%s -r%s',
@filename OUTPUT,
@message OUTPUT;
SELECT @filename,
@message;[!INCLUDE ssResult]
(No column name) (No column name)
---------------- --------------------
products10.tmp random