I have a stored procedure in SQL Server 2008, it accepts parameter and outputs a row with 15 columns. I have 100s of parameters to test with.
I do not want to waste time and execute it with each parameter individually and copy the result into an Excel sheet. I want all of them at once.
Can't I run the stored procedure with all the parameters one by one and get all the result in one table?
I have used cursor, I am providing i/ps but same thing, it gives me a separate table for each parameter and that means I have to copy each row one by one
e.g
DECLARE @field1 int
DECLARE cur CURSOR LOCAL FOR
SELECT t.PID
FROM dbo.TabletTEST t
WHERE t.Enumber IN (1, 2, 3, 4, 5, 6..100)
OPEN cur
FETCH NEXT FROM cur INTO @field1
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC [StoredProcedureToExecute] @field1
FETCH NEXT FROM cur INTO @field1
END
CLOSE cur
DEALLOCATE cur
1条答案
按热度按时间mctunoxg1#
You can use table valued function with Cross Apply. Please check msdn doc for Cross Apply example https://msdn.microsoft.com/en-us/library/ms175156.aspx