当前位置: 代码迷 >> Sql Server >> 这样的update能不能改得高效点解决思路
  详细解决方案

这样的update能不能改得高效点解决思路

热度:93   发布时间:2016-04-27 13:39:44.0
这样的update能不能改得高效点
SQL code
update MarketingCaseExpire set ProjectEndState=case  when DATEDIFF(month, getdate() , ProjectEndTime)=0 then '当月到期'when DATEDIFF(month, getdate() , ProjectEndTime)<0 then '已到期'when DATEDIFF(month, getdate() , ProjectEndTime)=1 then '下月到期'when DATEDIFF(month, getdate() , ProjectEndTime)>1 then '2个月后到期'end,CurrentMonthExpire=case  when DATEDIFF(month, getdate() , ProjectEndTime)=0 then 1else 0end,Expired=case  when DATEDIFF(month, getdate() , ProjectEndTime)<0 then 1else 0end,TwoMonthsAfterExpired=case  when DATEDIFF(month, getdate() , ProjectEndTime)>1 then 1else 0end,OneMonthsAfterExpired=case  when DATEDIFF(month, getdate() , ProjectEndTime)=1 then 1else 0end


------解决方案--------------------
应该可以了吧!再不行楼主可以分开更新,条件就是与当前日期的月份差,小于0和大于1分别更新。
------解决方案--------------------
楼主的语句就行了,语句简单没什么可优的
------解决方案--------------------
性能上没啥优化的,语句想看到短,那就把业务逻辑写到函数里面去
------解决方案--------------------
探讨

楼主的语句就行了,语句简单没什么可优的
  相关解决方案