日期:2014-05-17 浏览次数:20530 次
select Number400,Cyear,Cmonth,
FeeType,MobileOpenD,FixedFee,FeeTypeName,Fee1,Fee2,Fee3,Fee4,
Consumer1,Consumer2,Consumer3,Consumer4,
case when (Cyear>=datepart(yy,MobileOpenD) and Cmonth>=datepart(mm,MobileOpenD) and pay<FixedFee)
then FixedFee else pay end as pay
from
(
select a.Number400,b._year Cyear,b._Month Cmonth,a.FeeTypeName,a.FeeType,a.MobileOpenD,
a.FixedFee,a.Fee1,a.Fee2,a.Fee3,a.Fee4,
b.Consumer1,b.Consumer2,b.Consumer3,b.Consumer4,
case a.FeeType
when 1 then a.Fee1*b.Consumer1+a.Fee2*b.Consumer2
when 2 then a.Fee3*b.Consumer3+a.Fee4*b.Consumer4
end as pay
from S_Manager400 a
full join S_MonthlyData b on a.Number400=b.Number400
) t