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 2005 Forums
 Transact-SQL (2005)
 Obtain the row(s) affected in a variable

Author  Topic 

shifis
Posting Yak Master

157 Posts

Posted - 2009-09-11 : 15:04:28

Is posible to obtain the result of a select stament in a varible?

Example:
(291989 row(s) affected)

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-11 : 15:08:28
It is already captured in the global variable: @@rowcount

Be One with the Optimizer
TG
Go to Top of Page

shifis
Posting Yak Master

157 Posts

Posted - 2009-09-11 : 18:08:36
Thanks,

I am checking some stores that make a select to send information and then make a count of the select to obtain the number of rows sending.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-11 : 18:58:51
Just be careful because that value is reset after every statement. So:

select * from sysobjects
select @@rowcount
select @@rowcount

The second "select @@rowcount" will return 1. Because that was the rows affected from the first "select @@rowcount". If you need to save the value for a few statements then capture it in your own local variable:

declare @myRowcount int

select * from sysobjects
set @myRowcount = @@rowcount

Now you have your version for as long as you need.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -