select datediff(m,datecol,'2007-12-30')* 月租 + 
       case when datepart(d,datecol) > = 15 then 0.5 else 1.0 end *  月租
from t

解决方案 »

  1.   

    我想用sql数据库计算月租。某个时间X(如2007-10-16)开通的客户,第一个月,存在15号之前和之后的问题,15号之前算全价,15号之后算半价,之后的月份按全价算。如何用一个表达式计算X到12月份的月租。不用程序,直接在select   语句的表达式中实现
    ------少个开户时间.不好算.
      

  2.   


    select 价格 = ((datediff(month, X, convert(varchar(8), X, 120) + '31') +
    (case when datepart(dd, X) < 15 then 1 else 0.5 end)) * 月租
      

  3.   


    --3楼截止月份错了
    select 价格 = ((datediff(month, X, convert(char(4), year(X)) + '-12-31') +
    (case when datepart(dd, X) < 15 then 1 else 0.5 end)) * 月租
      

  4.   

    select case when month(开户时间) = 12 and day(开户时间) <= 15 then 0.5
                when month(开户时间) < 12 then datediff(month , 开户日期 , '2007-12-31') * 1.0
           end
    from tb
      

  5.   

    select datediff(m,datecol,datepart(y,datecol)+'-12-30')* 月租 + 
           case when datepart(d,datecol) > = 15 then 0.5 else 1.0 end *  月租
    from t
      

  6.   

    select datediff (m,X,'2007-12-30')*月租 -
    case when datepart(d,X)>=15 then 0.5 else 0.0 end  *月租
    from t
    我感觉是这个,别笑话,我新人