日期:2014-05-17  浏览次数:20310 次

求教一条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'