当前位置: 代码迷 >> Sql Server >> 求教一条update语句,该怎么解决
  详细解决方案

求教一条update语句,该怎么解决

热度:63   发布时间:2016-04-24 18:41:31.0
求教一条update语句
MSSQL
表defense_appuser,  update修改action_time>'2014-01-01'里的appstatus,
如果open_id在action_time<'2014-01-01'中存在,则更改的appstatus=0
如果open_id在action_time<'2014-01-01'中不存在,则appstatus不变
这条SQL怎么写?
------解决方案--------------------
update defense_appuser
set appstatus=case when action_time<'2014-01-01' then 0 else appstatus end 
where open_id=你要更新的id
------解决方案--------------------
试试这个:

 update defense_appuser
 set appstatus = 0 
 where open_id = xxx and action_time > '2014-01-01'
  相关解决方案