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.
MySQL ROW_COUNT() can be used to get the total number of rows affected by MySQL query. To illustrate it we are creating a procedure with the help of which we can insert records in a table and it will show us how many rows have been affected.
Usage. SQL Server @@ROWCOUNT is a system variable that is used to return the number of rows that are affected by the last executed statement in the batch.
DBCOUNT returns the number of rows affected by the last select statement executed by the stored procedure. For example, if the last two statements executed by the procedure are select and update statements, DBCOUNT returns the number of rows affected by the select, not by the update.
Get the Number of Rows Affected Using the execute() Method The execute() method returns true if the first result is a ResultSet object; it returns false if it is an update count or there are no results.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With