How to get result set of SQL Server stored procedure with parameter in a table or excel?

at0kjp5o  于 2023-10-15  发布在  SQL Server
关注(0)|答案(1)|浏览(150)

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

  1. DECLARE @field1 int
  2. DECLARE cur CURSOR LOCAL FOR
  3. SELECT t.PID
  4. FROM dbo.TabletTEST t
  5. WHERE t.Enumber IN (1, 2, 3, 4, 5, 6..100)
  6. OPEN cur
  7. FETCH NEXT FROM cur INTO @field1
  8. WHILE @@FETCH_STATUS = 0
  9. BEGIN
  10. EXEC [StoredProcedureToExecute] @field1
  11. FETCH NEXT FROM cur INTO @field1
  12. END
  13. CLOSE cur
  14. DEALLOCATE cur
mctunoxg

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

相关问题