TB1
应该返回时间 到达工厂时间 状态
2011-9-17 20:25
2011-9-17 20:25
2011-9-17 20:25
2011-9-20 20:15
2011-9-20 20:15
2011-9-20 20:15
求一更新语句-更新状态字段
判断到达工厂时间是否为空,如果不为空,用到达工厂时间-应该返回时间>0为迟到,否则为不迟到,如果为空,应该返回时间-当天日期,得出剩余返天数

解决方案 »

  1.   

    select case when 到达工厂时间='' then (case when datediff(d,到达工厂时间,应该返回时间)>0 then '迟到' else '正常' end) else cast(datediff(d,应该返回时间,getdate()) as varchar)+'天' end--未测试
      

  2.   

    是要这样的么:
    update tb1 set 状态=(case 
    when 到达工厂时间 is not null and 到达工厂时间>应该返回时间 then '迟到'
    when 到达工厂时间 is not null and 到达工厂时间<=应该返回时间 then '不迟到'
    else ltrim(datediff(d,到达工厂时间,getdate()))+'天'
    end)
      

  3.   

    update tb set 状态= case when colB is not null and datediff(dd,colA,colB)>0 then '迟到' when datediff(dd,colA,colB)<0 '不迟到' 
        when colB is null then ltrim(datediff(dd,getdate(),colA)) end
    --蹭点分