Hi all I need your help, how can you format a string with placeholders with the number of placeholders not known in advance (dynamic number of placeholders) ?
I need to do that in T-SQL
"xxxxx {0} yyyy {1} zzzz {2} "
with {} replaced by parameters.
I did the code:
with the results:
%s | %s | %s
a,b,c
a | b | c
but can I avoid the concatenation ' + @PARAMETERS + ' ?
If I don't use concatenation I get the error :
Error executing extended stored procedure: Invalid Parameter
Msg 50003, Level 1, State 0
Thanks :)
I need to do that in T-SQL
"xxxxx {0} yyyy {1} zzzz {2} "
with {} replaced by parameters.
I did the code:
Code:
DECLARE @PARAMETERS nvarchar(500) DECLARE @TEST nvarchar(500) DECLARE @QUERY nvarchar(500) SET @TEST = '%s | %s | %s' SET @PARAMETERS='a,b,c' SET @QUERY = ' PRINT @TEST; PRINT @PARAMETERS EXEC xp_sprintf @TEST out, @TEST,' + @PARAMETERS + ' PRINT @TEST' EXECUTE sp_executesql @QUERY,N'@TEST nvarchar(500), @PARAMETERS nvarchar(500)', @TEST,@PARAMETERS
with the results:
%s | %s | %s
a,b,c
a | b | c
but can I avoid the concatenation ' + @PARAMETERS + ' ?
If I don't use concatenation I get the error :
Error executing extended stored procedure: Invalid Parameter
Msg 50003, Level 1, State 0
Thanks :)
Comment