且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用T-SQL通过游标浏览存储过程的结果

更新时间:2023-02-06 07:53:32

您可以将存储过程中的结果放到临时表中,然后从中为您的光标选择。

You could drop the results from the stored proc into a temp table and select from that for your cursor.

CREATE TABLE #myResults
(
    Col1 INT,
    Col2 INT
)

INSERT INTO #myResults(Col1,Col2)
EXEC my_Sp

DECLARE sample_cursor CURSOR
FOR
 SELECT
    Col1,
    Col2
 FROM
    #myResults

另一种选择是将存储过程转换为表值函数。

Another option may be to convert your stored procedure into a table valued function.

DECLARE sample_cursor CURSOR
FOR
  SELECT
     Col1,
     Col2
  FROM
     dbo.NewFunction('foo', 'bar')