brgdotnet
asked on
@@ROWCOUNT is it automatically reset to Zero?
I have some SQL in a stored procedure that updates a table row at a time. It does this using a while loop.
After each UPDATE performed in the loop, I need to determine if the UPDATE was succesfull. From what I know I must use the NOCOUNT and RowCount commands to determine if the update was successful. So
will my @ROWCOUNT value be reset to 0 after each loop iteration, or would I need to explicitly reset it?
Below is my sql, however it is more pseudocode that working sql at this time.
ALTER PROCEDURE YourProcName
@Opmessage VARCHAR(100) OUTPUT
AS
DECLARE @i INT
DECLARE @UpperBound INT
SELECT @i = 0
SELECT @UpperBound = 10
WHILE @i < @UpperBound
BEGIN SET NOCOUNT ON;
UPDATE Table SET Table.Name ='Shaked' where Table.ID =@i1
SET @I = @I + 1
END
IF (@@ROWCOUNT > 0)
BEGIN
@Opmessage = 'Success!'
END
ELSE
BEGIN
@Opmessage = 'Not success!'
END
END -- End of while loop
After each UPDATE performed in the loop, I need to determine if the UPDATE was succesfull. From what I know I must use the NOCOUNT and RowCount commands to determine if the update was successful. So
will my @ROWCOUNT value be reset to 0 after each loop iteration, or would I need to explicitly reset it?
Below is my sql, however it is more pseudocode that working sql at this time.
ALTER PROCEDURE YourProcName
@Opmessage VARCHAR(100) OUTPUT
AS
DECLARE @i INT
DECLARE @UpperBound INT
SELECT @i = 0
SELECT @UpperBound = 10
WHILE @i < @UpperBound
BEGIN SET NOCOUNT ON;
UPDATE Table SET Table.Name ='Shaked' where Table.ID =@i1
SET @I = @I + 1
END
IF (@@ROWCOUNT > 0)
BEGIN
@Opmessage = 'Success!'
END
ELSE
BEGIN
@Opmessage = 'Not success!'
END
END -- End of while loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.