Goal: Call the existing stored procedure many times with different sets of values, e.g. Parameter 1 {100000, 100001, 100002....}, ....
dbo.ExistingStoredProc
= existing stored procedure that takes 2 parameters {int, varchar(20)}
I use table valued parameters for this task. However, it's a real mess to modify the existing stored procedure to replace the two parameters with one table valued parameter. So I thought about creating another stored procedure with table valued parameter then call the existing stored procedure. Is this possible?
dbo.CallingStoredProc
= stored procedure with table valued parameter and calls dbo.ExistingStoredProc
dbo.CallingStoredProc
(simplified to 1 parameter)
@TvpParameter tvpMyType READONLY
Declare @sn int
Select @sn = SerialNumber from @TvpParameter
EXEC dbo.ExistingStoredProc @sn
Modified script that executes dbo.CallingStoredProc
DECLARE @TvpParameter AS dbo.tvpMyType
INSERT INTO @TvpParameter (SerialNumber) VALUES (123456), (654321)
DECLARE @return_value int
EXEC @return_value = dbo.CallingStoredProc
@tvpExistingPar = @TvpParameter
SELECT 'Return Value' = @return_value
RESULT
I only get the result for the last item in TVP, which is SerialNumber = 654321.