Help to return var and recordset

  • Hi,

    Is there any way to return variable and recordset, for example

    if object_id('return_var_and_recordset') is not null

     drop procedure return_var_and_recordset

    go

    create procedure return_var_and_recordset(@date datetime output)

    as

    SET NOCOUNT ON

    SET @date = CURRENT_TIMESTAMP

    SELECT TOP 10 * FROM Temp

    go

     

    If you have any ideas please help on this.

     

    I got the solution at

    http://www.aspfree.com/c/a/DatabaseCode/Execute-stored-proc-having-input-and-output-params-returned-recordset-and-return-value/

  • You can't use the Table data type in stored procedures.

     

     

  • yes you can:

    Create Table TEST (Row int, Data varchar(60))

    GO

    INSERT INTO TEST VALUES (1, 'a')

    INSERT INTO TEST VALUES (2, 'ab')

    INSERT INTO TEST VALUES (3, 'abc')

    INSERT INTO TEST VALUES (4, 'abcd')

    INSERT INTO TEST VALUES (5, 'abcde')

    INSERT INTO TEST VALUES (6, 'abdcef')

    if object_id('return_var_and_recordset') is not null

     drop procedure return_var_and_recordset

    go

    create procedure return_var_and_recordset(@date datetime output)

    as

    SET NOCOUNT ON

    SET @date = CURRENT_TIMESTAMP

    SELECT TOP 10 * FROM Test

    go

    Declare @Tmp datetime

    Create Table #T1(Row int, Data varchar(60))

    Insert into #T1(Row , Data ) Exec return_var_and_recordset @Tmp output

    select * from #T1

    Select @Tmp

    drop table #T1

    go

    Drop table TEST

    go

     

    Row         Data                                                        

    ----------- ------------------------------------------------------------

    1           a

    2           ab

    3           abc

    4           abcd

    5           abcde

    6           abdcef

    (6 row(s) affected)

                                                          

    ------------------------------------------------------

    2004-03-25 12:25:44.007

    (1 row(s) affected)

    qed


    * Noel

  • Thank you very much.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply