Can't get rowcount to return to calling stored procedure

  • SQL Server 2012 Standard SP 1.

    Stored procedure A calls another stored procedure B. Rowcount is set properly in called procedure B, but does not seem to return it to calling procedure A. Otherwise the two stored procedures are working correctly. Here is the relevant code from the calling procedure A:

    declare @NumBufferManagerRows int = 0;

    exec persist.LoadBufferManager @StartTicks, @EndTicks, @TimeDiff, @NumBufferManagerRows;

    print 'BufferManagerRows';

    print @NumBufferManagerRows;

    Print statement prints @NumBufferManagerRows as 0.

    Here is the called stored procedure B:

    CREATE PROCEDURE [persist].[LoadBufferManager]

    -- Add the parameters for the stored procedure here

    @StartTicks bigint,

    @EndTicks bigint,

    @TimeDiff decimal(9,2),

    @NumRows int OUTPUT

    ...

    (insert statement)

    set @NumRows = @@ROWCOUNT;

    print 'LoadBufferManager NumRows';

    print @NumRows;

    END

    Print statement prints @NumRows as 38060.

    I appreciate your help, thanks!

  • Nicole Garris (7/9/2014)


    SQL Server 2012 Standard SP 1.

    Stored procedure A calls another stored procedure B. Rowcount is set properly in called procedure B, but does not seem to return it to calling procedure A. Otherwise the two stored procedures are working correctly. Here is the relevant code from the calling procedure A:

    declare @NumBufferManagerRows int = 0;

    exec persist.LoadBufferManager @StartTicks, @EndTicks, @TimeDiff, @NumBufferManagerRows;

    print 'BufferManagerRows';

    print @NumBufferManagerRows;

    Print statement prints @NumBufferManagerRows as 0.

    Here is the called stored procedure B:

    CREATE PROCEDURE [persist].[LoadBufferManager]

    -- Add the parameters for the stored procedure here

    @StartTicks bigint,

    @EndTicks bigint,

    @TimeDiff decimal(9,2),

    @NumRows int OUTPUT

    ...

    (insert statement)

    set @NumRows = @@ROWCOUNT;

    print 'LoadBufferManager NumRows';

    print @NumRows;

    END

    Print statement prints @NumRows as 38060.

    I appreciate your help, thanks!

    exec persist.LoadBufferManager @StartTicks, @EndTicks, @TimeDiff, @NumBufferManagerRows output;

    You have to tell the calling procedure that the parameter is an output parameter.

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Very nice! Made the change, now printing the number of rows in calling procedure A produces:

    35422

    which is the correct value. Thanks!

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

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