5

Below is my query

select    
@monNameStr as [MName],             
IsNull(count(c.AssignmentID),0),                
IsNull(sum(s.ACV),0),               
IsNull(sum(s.GrossReturn),0),               
IsNull(sum(s.NetReturn),0),             
IsNull(avg(a.Total),0)          
FROM

dbo.Assignment_ClaimInfo c,             
dbo.Assignment_SettlementInfo s,                
dbo.Assignment_AdvCharges a         

Where
c.Assignmentid=s.Assignmentid and               
s.Assignmentid=a.Assignmentid and               
a.Assignmentid in                   

(select AssignmentID from dbo.Assignment_ClaimInfo                  
where (upper(InsuranceComp)=upper(@CompName) or upper(@CompName)='ALL COMPANIES') 
and (DateName(month,DATEADD(month, 0, DOFileClosed))+' '
+cast(year(DATEADD(month, 0, DOFileClosed)) as varchar)=@monNameStr))
Group By c.InsuranceComp
Order By c.InsuranceComp

where @monNameStr is calculated date field like 'October 2009'

What i need to know the no. of records affected by this select query.

I DONT NEED TO NEST THIS QUERY TO ANOTHER QUERY WITH COUNT() FUNCTION.

Your valuable help is appreciated.

Binoj Antony
  • 15,886
  • 25
  • 88
  • 96
IrfanRaza
  • 3,030
  • 17
  • 64
  • 89

4 Answers4

5

capture @@ROWCOUNT into a variable, because it will change values each time you select it:

DECLARE @Rows   int

---your query here

SELECT @Rows=@@ROWCOUNT

you can then use it as necessary as @Rows

KM.
  • 101,727
  • 34
  • 178
  • 212
1

You can check the value of @@ROWCOUNT after the query has run. See http://technet.microsoft.com/en-us/library/ms187316.aspx for more info.

TLiebe
  • 7,913
  • 1
  • 23
  • 28
1
select @@ROWCOUNT 

(e.g. Counting the number of deleted rows in a SQL Server stored procedure )

Community
  • 1
  • 1
Unsliced
  • 10,404
  • 8
  • 51
  • 81
1
You can just use `@@ROWCOUNT` to get the records affected/returned

DECLARE @rowsreturned INT
SET @rowsreturned = @@ROWCOUNT
Binoj Antony
  • 15,886
  • 25
  • 88
  • 96