SELECT agentid=dc.AgentID,AmtPeroid=dc.AmtPeroid,AgentCode=mg.AgentCode,AgentName=mg.AgentName,
Position=mu.Position,savedate=mc.SaveDate
FROM tbDCusCardS dc
inner join tbMAgent mg on dc.AgentID = mg.AgentID
left join tbMUser mu on mg.AgentCode = mu.UserName
inner join tbMCardS mc on dc.CardSNo = mc.CardSNo
Tag : .NET, Ms SQL Server 2005, Ms SQL Server 2008, C#
Date :
2011-06-29 12:21:01
By :
mushroomsn
View :
1090
Reply :
1
No. 1
Guest
Code (C#)
WITH [AgentQuery] (AmtPeroid ,AgentCode, AgentName, ) AS
(
SELECT AmtPeroid=dc.AmtPeroid, AgentCode=mg.AgentCode
, AgentName=mg.AgentName
FROM tbDCusCardS dc
inner join tbMAgent mg
on dc.AgentID = mg.AgentID
left join tbMUser mu
on mg.AgentCode = mu.UserName
inner join tbMCardS mc
on dc.CardSNo = mc.CardSNo
)
SELECT COUNT([AgentCode]) As [Frequency]
,[AgentName] AS [Name], SUM([AmtPeroid ]) AS [Amount]
FROM [AgentQuery]
GROUP BY [AgentCode] ,[AgentName]