以下是我的查询
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'
我需要知道的是什么。受此选择查询影响的记录。
我不需要用COUNT()函数将这个查询到另一个查询。
非常感谢您的宝贵帮助。
答案 0 :(得分:5)
将@@ ROWCOUNT捕获到变量中,因为每次选择它时都会更改值:
DECLARE @Rows int
---your query here
SELECT @Rows=@@ROWCOUNT
然后您可以根据需要使用@Rows
答案 1 :(得分:1)
查询运行后,您可以检查@@ ROWCOUNT的值。有关详细信息,请参阅http://technet.microsoft.com/en-us/library/ms187316.aspx。
答案 2 :(得分:1)
select @@ROWCOUNT
(例如Counting the number of deleted rows in a SQL Server stored procedure)
答案 3 :(得分:1)
You can just use `@@ROWCOUNT` to get the records affected/returned
DECLARE @rowsreturned INT
SET @rowsreturned = @@ROWCOUNT