2009-10-09 76 views
5

運行選擇查詢後行的下面是我的查詢獲取否。受影響的SQL Server 2005中

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)[email protected])) 
Group By c.InsuranceComp 
Order By c.InsuranceComp 

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

我需要知道什麼沒有。受此選擇查詢影響的記錄。

我不需要使用COUNT()函數將此查詢納入其他查詢。

您的寶貴幫助表示讚賞。

回答

5

捕獲@@ ROWCOUNT到一個變量,因爲它會在每次更改值,您選擇它:

DECLARE @Rows int 

---your query here 

SELECT @[email protected]@ROWCOUNT 

然後你可以使用它作爲必要的@Rows

+1

謝謝KM, 你是男人!!! – IrfanRaza 2009-10-09 13:25:33

1
You can just use `@@ROWCOUNT` to get the records affected/returned 

DECLARE @rowsreturned INT 
SET @rowsreturned = @@ROWCOUNT 
相關問題