August 23, 2010 at 2:12 am
When executing the following statement:
sp_executesql N'select * from table1; select * from table2 go select * from table3'
If i were then to exec SELECT @@ROWCOUNT it would only return the number of rows from the last select statement (table3).
Other than parsing the string for all statement and batch terminators and then executing each statement and @@ROWCOUNT is there another way that i can retrieve the number of rows. For example the Query> Messages tab shows the number of rows affected by each stmt?
August 23, 2010 at 3:50 am
@@ROWCOUNT will return the affected rows based on the statement before @@ROWCOUNT.
You don't have to look for batch terminator.
Other than that, yes, you'd have to look for each statement where you'd like to know the number of affected rows. But instead of running each statement separately you could assign the result to separate variables and select those at the very end of your batch:
sp_executesql N'DECLARE @t int
DECLARE @t2 int
SELECT * from table1
SELECT @t=@@ROWCOUNT
SELECT * from table2
SELECT @t2=@@ROWCOUNT
SELECT @t,@t2'
August 23, 2010 at 3:53 am
Thanks for your reply LutzM.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy