Basic Question - @@ROWCOUNT Returning Zero from Stored Proc SQL S 7

M

Mike Thomas

I am new to SQL Server & using SQL 7 with Access. The stored proc below
always returns zero in the @IntRecCount parameter. If I substute a number
for @@ROWCOUNT, the proc will correclty return that number.

But for some reason, @@ROWCOUNT always puts a zero into @IntRecCount. Is
there any obvious reason for this? I know the correct records are being
updated in the table - I can see it after running the proc.

Thanks
Mike Thomas


CREATE PROCEDURE _PayMile
@strString varchar(8)=Null,
@intMonth int = Null,
@IntRecCount int = Null OUTPUT,
@RetMsg varchar(50) = Null OUTPUT

AS
DECLARE @Err int

Update mileage set mlgpaid = 1
where (mlgpaid = 0 or mlgpaid is null) and tripdate <= @strString

SELECT @Err = @@ERROR
IF (@Err <> 0) GOTO HandleErr

SELECT @IntRecCount = @@ROWCOUNT
SELECT @RetMsg = " Records Updated"

RETURN

HandleErr:
SELECT @IntRecCount = -1
SELECT @RetMsg = "Error in SP: " + CONVERT(VarChar, @Err)
RETURN
 
J

J. M. De Moor

Mike
SELECT @IntRecCount = @@ROWCOUNT

Try

SET @IntRecCount = @@rowcount;

....and put it right after the UPDATE statement. Always use SET when
assigning variables that are not being accessed from a table or view.

Joe
 
V

Vadim Rapp

MT> SELECT @Err = @@ERROR
MT> IF (@Err <> 0) GOTO HandleErr

MT> SELECT @IntRecCount = @@ROWCOUNT
MT> SELECT @RetMsg = " Records Updated"

@@rowcount represents the result of the preceding select, which is select
@err=@@error

Vadim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top