日期:2014-05-18 浏览次数:20922 次
declare @time2 datetime select @time2='2012-1-31' select a.TypeOfPayment,a.LeaseDateFrom, (case when a.TypeOfPayment like '%月末%' then DATEDIFF(mm, DATEADD (MONTH ,-1,a.LeaseDateFrom), @time2)/12*12*a.MonthRent + (DATEDIFF (MM,DATEADD (MONTH ,-1,a.LeaseDateFrom),@time2)%12+1)*a.MonthRent when TypeOfPayment='季度末7日前预交1、4、7、10' and ((DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))=1) or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))=4) or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))=7) or (DATEPART(month,DATEADD (DD,-7,a.LeaseDateFrom))=10)) then DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)/12*a.MonthRent + DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)%12/3*3*a.MonthRent +3*a.MonthRent when TypeOfPayment='季度末7日前预交1、4、7、10' and ((DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>1) or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>4) or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>7) or (DATEPART(month,DATEADD (DD,-7,a.LeaseDateFrom))<>10)) and DATEPART (MONTH,@time2)>DATEPART (MONTH ,a.LeaseDateFrom ) then DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)/12*a.MonthRent + DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)%12/3*3*a.MonthRent +3*MonthRent when TypeOfPayment='季度末7日前预交1、4、7、10' and ((DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>1) or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>4) or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>7) or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>10)) and DATEPART (MONTH,@time2)<DATEPART (MONTH ,a.LeaseDateFrom) then DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)/12*a.MonthRent + DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)%12/3*3*a.MonthRent else null end) as 总应收 from ContractTable a join PropertyTable b on a.City +a.Road +a.[Address] =b.City +b.Road +b.[Address]
declare @time2 datetime
select @time2='2012-1-31'
select a.TypeOfPayment,a.LeaseDateFrom,
(case
when a.TypeOfPayment like '%月末%'
then DATEDIFF(mm, DATEADD (MONTH ,-1,a.LeaseDateFrom), @time2)/12*12*a.MonthRent +
(DATEDIFF (MM,DATEADD (MONTH ,-1,a.LeaseDateFrom),@time2)%12+1)*a.MonthRent
when TypeOfPayment='季度末7日前预交1、4、7、10' then
case
when ((DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))=1)
or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))=4)
or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))=7)
or (DATEPART(month,DATEADD (DD,-7,a.LeaseDateFrom))=10))
then DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)/12*a.MonthRent +
DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)%12/3*3*a.MonthRent +3*a.MonthRent
when ((DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>1)
or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>4)
or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>7)
or (DATEPART(month,DATEADD (DD,-7,a.LeaseDateFrom))<>10))
and DATEPART (MONTH,@time2)>DATEPART (MONTH ,a.LeaseDateFrom )
then DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)/12*a.MonthRent +
DATEDIFF (MM,dateadd(DD ,-7, a.LeaseDateFrom),@time2)%12/3*3*a.MonthRent +3*MonthRent
when ((DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>1)
or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>4)
or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>7)
or (DATEPART(month, DATEADD (DD,-7,a.LeaseDateFrom))<>10))
an