Groups | Blog | Home
all groups > sql server programming > january 2004 >

sql server programming : Way to Reset @@rowcount



CSharp ( ILM )
1/30/2004 9:50:59 PM
hello,

is there a way to reset @@rowcount to zero

if I have multiple inserts one after another
I can't rely on @@rowcount because it does not always reflect the last
insert
if one of inserts fails then the @@rowcount keeps its value from the
previous Insert

Am I wrong??

SAM

CSharp ( ILM )
1/30/2004 10:35:54 PM
What if there was an error?
I have see it differently

SAM

[quoted text, click to view]

Dejan Sarka
1/31/2004 11:02:57 AM
[quoted text, click to view]

Can you give us an example? If ou look at this

SET NOCOUNT ON
GO
SELECT *
FROM dbo.Region
GO
INSERT INTO dbo.Region VALUES (5, 'a')
SELECT @@rowcount AS 'Rcnt'
INSERT INTO dbo.Region VALUES (6, 'a')
INSERT INTO dbo.Region VALUES (6, 'a')
SELECT @@rowcount AS 'Rcnt'
GO
DELETE FROM dbo.Region
WHERE RegionID > 4
SELECT *
FROM dbo.Region
GO

you will notice that it works as expected.

--
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com

Roji. P. Thomas
1/31/2004 11:52:33 AM
You are wrong.
@@ROWCOUNT holds the no od records affected by last statement.
If no records affected then its value is zero.


--
Roji. P. Thomas
SQL Server Programmer
--------------------------------------
[quoted text, click to view]

Hari Prasad
1/31/2004 3:47:55 PM
Hi,

During error situations, @@rowcount will return '0' (Zero)

Thanks
Hari
MCDBA
[quoted text, click to view]

AddThis Social Bookmark Button