从存储过程返回结果集

时间:2013-04-24 11:37:42

标签: sql-server stored-procedures

假设我为存储过程做了必要的声明并开始存储过程

BEGIN

IF (@TYPE = 0)  
    BEGIN
        SELECT @AMOUNT = ((@TOTAL_MONEY )/(12))
        SELECT @INTEREST_AMOUNT = 0           
        SELECT @TOTAL_MONEY AS TOTAL_MONEY , @AMOUNT AS AMOUNT , @INTEREST_AMOUNT AS INTEREST_AMOUNT , DATEADD(m,0,@BEGIN_DATE) AS DATE_

        @ORDER_NO=1 
        WHILE ((@ORDER_NO) <= ((@COUNT) -1 ) )  
            BEGIN   
                SELECT @INTEREST_AMOUNT =  (@TOTAL_MONEY - (@AMOUNT))* (@INTEREST_RATE/100)
                SELECT @MONEY AS MONEY_ , @AMOUNT AS PROMISE_AMOUNT , @INTEREST_AMOUNT AS INTEREST_AMOUNT , DATEADD(m,@COUNT,@BEGIN_DATE) AS DATE_
                SELECT @COUNT=@COUNT -1
            END                     
    END 
 END

问题是:我想转一个结果集但是这个程序一行一行 所以我创建了一个临时表并选择如下,但我不想使用临时表,只是从我的存储过程返回结果集

DECLARE @TEMP TABLE
(

    TOTAL_MONEY decimal (19,3), 
    AMOUNT decimal (19,3), 
    INTEREST_AMOUNT decimal (19,3), 
    DATE_ date          

);
INSERT @TEMP  EXEC --HERE I CALL MY STORED PROCESURE with parameters IE: spinterest ..., ...., ...
SELECT * FROM @TEMP;

1 个答案:

答案 0 :(得分:0)

将代码的最后两行更改为以下一行:

EXEC --HERE I CALL MY STORED PROCESURE with parameters IE: spinterest ..., ...., ...

我不知道你的参数是什么样的,但是,你说它们已经设置好了。