我有一查询语句select 提醒日期 from A现在我查出的表有两列,分别是 [提醒日期][剩余天数]
如果剩余天数为小于0就显示为0请问这样的查询语句应该如何写? 剩余天数=提醒日期-当天日期
是否可以用IF判断,不知如何写?谢谢

解决方案 »

  1.   

    select case when datediff(day,getdate(),提醒日期)<0 then 0 else datediff(day,getdate(),提醒日期) end
    from a
      

  2.   

    select 提醒日期 , case when 剩余天数 < 0 then 0 else 剩余天数 end 剩余天数 from A from tbselect 提醒日期 , case when 提醒日期 < 当天日期 then 0 else datediff(day , 当天日期 , 提醒日期) end 剩余天数 from A from tb
      

  3.   

    select 提醒日期,
           case when datediff(day,getdate(),提醒日期)<0 
                then 0 
                else datediff(day,getdate(),提醒日期) 
           end
    from tb
      

  4.   


    select 提醒日期,
           case when datediff(day,getdate(),提醒日期)<0 
                then 0 
                else datediff(day,getdate(),提醒日期) 
           end as 剩余天数
    from tb