Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
@@Rowcount is not reliable?
@@Rowcount is not reliable?
Rate Topic
Display Mode
Topic Options
Author
Message
Raghavendra-499237
Raghavendra-499237
Posted Wednesday, June 03, 2009 1:51 AM
SSChasing Mays
Group: General Forum Members
Last Login: Monday, June 04, 2012 7:17 AM
Points: 606,
Visits: 333
I have used @@RowCount next to one update statement in a stored procedure.
It was working fine in one of our production database, but recently we observed sometimes it will not work properly.
is @@RowCount is not reliable?
please advice.
Post #727944
Sergiy
Sergiy
Posted Wednesday, June 03, 2009 2:16 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: 2 days ago @ 6:59 PM
Points: 4,557,
Visits: 8,215
It never failed on my memory.
Unexpected results it returned only in cases when it was used incorrectly.
Can you show your code?
But don't modify anything, every detail may be very important.
Post #727954
Raghavendra-499237
Raghavendra-499237
Posted Wednesday, June 03, 2009 4:11 AM
SSChasing Mays
Group: General Forum Members
Last Login: Monday, June 04, 2012 7:17 AM
Points: 606,
Visits: 333
Hi Sergiy,
my stored procedure is as follows..
basically this procedure should return @NewStatus only once if it is called multiple times for a given @ID
UPDATE Table SET Status=@NewStatus WHERE ID=@ID AND Status=@CurrentStatus
IF @@ROWCOUNT=1
RETURN @NewStatus
ELSE
RETURN @CurrentStatus
Post #728030
Sergiy
Sergiy
Posted Wednesday, June 03, 2009 4:24 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: 2 days ago @ 6:59 PM
Points: 4,557,
Visits: 8,215
Try to run this:
SELECT ID, Status, COUNT(*)
FROM Table
GROUP BY ID, Status
HAVING COUNT(*) > 1
Post #728036
EdVassie
EdVassie
Posted Thursday, June 04, 2009 7:09 AM
SSCrazy
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 3:26 AM
Points: 2,621,
Visits: 2,759
You have to be careful when using @@ROWCOUNT. Your example should work as you expect, but the example below will not...
UPDATE .....
SELECT @MyErr = @@ERROR
IF @@ROWCOUNT > 1 ...
In this situation @@ROWCOUNT will always be 1 because of the SELECT running after the update that saves the error code.
If you need to save both the @@ERROR and @@ROWCOUNT values, use something similar to the code below. You can then refer to @MyErr and @MyCount whenever you want and always get the values from the UPDATE statement.
UPDATE...
SELECT @MyErr = @@ERROR, @MyCount = @@ROWCOUNT
Author:
SQL Server FineBuild
1-click install and best practice configuration of SQL Server 2012, 2008 R2, 2008 and 2005.
25 March 2013
: now over 23,000 downloads.
Disclaimer: All information provided is a personal opinion that may not match reality.
Concept: "Pizza Apartheid" - the discrimination that separates those who earn enough in one day to buy a pizza if they want one, from those who can not.
Post #728911
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.