日期:2014-05-17 浏览次数:20504 次
select bbd.Operate_Name as '经营单位',cmf.AllotDepartment as '分配部门',cmf.CostName as '费用名称'
--,(count(case when CostType='0' and Flag_ClosingCost='1' then bbd.Consignor else 0 end))
,sum(case when CostType='0' and Flag_ClosingCost='1' then ShouldMoney else 0 end)*(Currency_Rate) as '应收金额'
,sum(case when CostType='1' and Flag_ClosingCost='1' then ShouldMoney else 0 end)*(Currency_Rate) as '应付金额'
,sum(case when CostType='0' and Flag_ClosingCost='1' then ShouldMoney else 0 end)*(Currency_Rate) -sum(case when CostType='1' and Flag_ClosingCost='1' then ShouldMoney else 0 end)*(Currency_Rate) as '毛利润'
,sum([Money]) as '管理费用'
,((sum(case when CostType='0' and Flag_ClosingCost='1' then ShouldMoney else 0 end)*(Currency_Rate) -sum(case when CostType='1' and Flag_ClosingCost='1' then ShouldMoney else 0 end)*(Currency_Rate) )-sum([Money])) as '纯利润'
from [cost_FeeInfo] as cfi,bus_BusinessDetail as bbd,cost_ManageFee as cmf
where cfi.BusinessNum=bbd.BusinessNum and cmf.Consignor = bbd.Operate_Name and bbd.IsAvailable='True'
and Flag_ClosingCost='1'
AND bbd.InputDate BETWEEN '2013-05-01 00:00:00' AND '2013-05-31 00:00:00'
AND cmf.CreateDate BETWEEN '2013-05-01 00:00:00' AND '2013-05-31 00:00:00'
GROUP BY bbd.Operate_Name,cmf.AllotDepartment,[Money],Currency_Rate,cmf.CostName