Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 @@rowcount wrong using a two server query

Author  Topic 

addinsell
Starting Member

2 Posts

Posted - 2009-06-30 : 07:24:03
Hi
I have a delete query which links a table in a remote server with a table in a local server and deletes a few records in my local server.
The problem is that @@rowcount is returning the count of the remote server records retrieved in evaluating the query. I can see this in the execution plan.
How do I get the number of records affected in the delete.?

delete localtable from
localtable inner join remotetable on localtable.key = remotetable.key
select @@rowcount

There are 20 different remotetable.key values, none match the localtable.key and so 0 records are deleted but the @@rowcount returns 20.

The same sort of problem occurs on an insert query except that the count of 20 remote records is 'added' to the count of records actually inserted.

HELP !

Thx Ian

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-06-30 : 08:44:58
http://msdn.microsoft.com/en-us/library/ms187316(SQL.90).aspx
Go to Top of Page

addinsell
Starting Member

2 Posts

Posted - 2009-07-01 : 11:23:53
The link does not enlighten me I am afraid. It describes what I had expected @@rowcount to do. Not what it does for me in the scenario described. The sample code on that page shows that if an update updates no rows then @@rowcount will be zero. I have @@rowcount returning a value of 20 when NO records are deleted. I think it is reasonable to expect the two scenarios to behave the same way.
Go to Top of Page
   

- Advertisement -