2009-10-09 10 views
5

は、私のクエリは、私はありませんが知っておく必要がありますどのようないいえ。以下は、SQL Server 2005でSELECTクエリを実行した後に、影響を受けた行の

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' 

です。この選択クエリの影響を受けるレコードの数。

私はこのクエリをカウント()機能付きの別のクエリにネストする必要はありません。

貴重なご支援をいただきありがとうございます。

答えて

5

キャプチャ@@変数にROWCOUNT、それは値にあなたがそれを選択するたびに変更されますので:

DECLARE @Rows int 

---your query here 

SELECT @[email protected]@ROWCOUNT 

あなたはその後、@Rowsとして、必要に応じてそれを使用することができます

+1

ありがとうKM あなたは男です! – IrfanRaza

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

DECLARE @rowsreturned INT 
SET @rowsreturned = @@ROWCOUNT 
関連する問題