T-Sql 如何从另一个存储过程中的存储过程返回表

T-Sql 如何从另一个存储过程中的存储过程返回表

问题描述:

我想做以下事情.基本上有一个存储过程调用另一个返回表的存储过程.这是怎么做的?

I would like to do the following. Basically have a stored procedure call another stored procedure that returns a table. How is this done?

    ALTER PROC [GETSomeStuff]
    AS
    BEGIN

    @table = exec CB_GetLedgerView @accountId, @fromDate, @toDate, @pageSize, @pageNumber, @filter, @status, @sortExpression, @sortOrder, @virtualCount OUTPUT

   Select * from @table
   --Do some other stuff here        
    END

存储过程的目标必须是临时表或实际表,以便您可以

The target of a stored procedure has to be a temp or actual table so you can

    Insert into #table exec CB_GetLedgerView @accountId, @fromDate, 
@toDate, @pageSize, @pageNumber, 
@filter, @status, @sortExpression, 
@sortOrder, @virtualCount OUTPUT

如果存储过程的输出结果集与目标表中的序号位置和行数不匹配,则指定一个列列表.

If the output result set of the stored procedure does not match the ordinal positions and count of the rows in the target table, specify a column list.