Highlighted
New Member.
2231 views

SQL Interaction and @@ROWCOUNT

Jump to solution

Is there any way when processing a SQL statement (SELECT, INSERT, UPDATE, DELETE) to retrieve the results of @@ROWCOUNT to establish how many rows were affected by the statement?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: SQL Interaction and @@ROWCOUNT

Jump to solution

I believe that SQL Server maintains a separate @@ROWCOUNT for each Connection/transaction. I checked this with 2 SQL queries.

View solution in original post

0 Likes
4 Replies
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: SQL Interaction and @@ROWCOUNT

Jump to solution

The following code works for me:

          exec sql delete Identity_Nummer

                    where Nummer = 0

          end-exec

          declare  rowCount as binary-long.

          exec sql select @@rowcount

                     into :rowCount

          end-exec.

0 Likes
Highlighted
New Member.

RE: SQL Interaction and @@ROWCOUNT

Jump to solution

Thanks for your response.

Your code does work however in an OLTP type environment there is a reasonable chance that @@ROWCOUNT will have been reset by another interaction that has occurred between the time of the deletion and you submitting the query to retrieve it.

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: SQL Interaction and @@ROWCOUNT

Jump to solution

I believe that SQL Server maintains a separate @@ROWCOUNT for each Connection/transaction. I checked this with 2 SQL queries.

View solution in original post

0 Likes
Highlighted
New Member.

RE: SQL Interaction and @@ROWCOUNT

Jump to solution

Thanks for your response I will give this a try and see whether it all works.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.