--参考:select distinct department from PriorToCapDistribution
select * from PriorToCapDistributionitem a
left join PriorToCapDistribution b
on a.mainid=b.mainid where b.department='再制造'
select b.Department,
case when Department='阀门' then (isnull((select SUM(EngineeringEquip) from
PriorToCapDistributionItem e inner join PriorToCapDistribution f on
e.MainID=f.MainID
inner join JHOA_Approve c
on f.MainID=c.AppO_Values and c.App_Over=1 and
c.App_IdeaFlag=9 and c.Del_flag=0
where f.Department='再制造'
--[@ and f.[Year]=:year @] [@ and f.[Month]=:month @]
and f.year='2012' and f.month='5'
group by f.Department
),0)*0.17)+SUM(isnull(EngineeringEquip,0))
when Department='气瓶' then (isnull((select SUM(EngineeringEquip) from
PriorToCapDistributionItem e inner join PriorToCapDistribution f on
e.MainID=f.MainID
inner join JHOA_Approve c
on f.MainID=c.AppO_Values and c.App_Over=1 and
c.App_IdeaFlag=9 and c.Del_flag=0
where f.Department='再制造'
--[@ and f.[Year]=:year @] [@ and f.[Month]=:month @]
and f.year='2012' and f.month='5'
group by f.Department
),0)*0.36)+SUM(isnull(EngineeringEquip,0))
when Department='撬装' then (isnull((select SUM(EngineeringEquip) from
PriorToCapDistributionItem e inner join PriorToCapDistribution f on
e.MainID=f.MainID
inner join JHOA_Approve c
on f.MainID=c.AppO_Values and c.App_Over=1 and
c.App_IdeaFlag=9 and c.Del_flag=0
where f.Department='再制造'
--[@ and f.[Year]=:year @] [@ and f.[Month]=:month @]
and f.year='2012' and f.month='5'
group by f.Department
),0)*0.28)+SUM(isnull(EngineeringEquip,0))
when Department='重工' then (isnull((select SUM(EngineeringEquip) from
PriorToCapDistributionItem e inner join PriorToCapDistribution f on
e.MainID=f.MainID inner join JHOA_Approve c
on f.MainID=c.AppO_Values and c.App_Over=1 and
c.App_IdeaFlag=9 and c.Del_flag=0 where f.Department='再制造'
--[@ and f.[Year]=:year @] [@ and f.[Month]=:month @]
and f.year='2012' and f.month='5'
group by f.Department
),0)*0.19)+SUM(isnull(EngineeringEquip,0))
when Department='韩中' then SUM(isnull(EngineeringEquip,0))
when Department='工程事业部' then SUM(isnull(EngineeringEquip,0))
else 0
end as EngineeringEquip
from PriorToCapDistributionItem a
inner join PriorToCapDistribution b
on a.MainID=b.MainID
inner join JHOA_Approve c
on b.MainID=c.AppO_Values
and c.App_Over=1 and c.App_IdeaFlag=9 and c.Del_flag=0
where department !='瓶撬'
--[@ and b.[Year]=:year @] [@ and b.[Month]=:month @]
and b.year='2012' and b.month='5'
group by b.Department,a.remark