表a 字段 a(datetime),b(int)
我想让当 a中的时间小于当前时间的时候,更新 b字段值为1。应该怎么处理?
这个需求的用途是,购物网站,当过期时间小于当前时间的时候,就判断此信息过期,则更新状态字段为过期。
谢谢啦~~
------解决方案--------------------
- SQL code
create table 表a(a datetime,b int)insert 表a values('1988-01-02',0)update 表a set b=1 where a<getdate()select * from 表adrop table 表a/*a b ------------------------------------------------------ ----------- 1988-01-02 00:00:00.000 1(所影响的行数为 1 行)*/
------解决方案--------------------
- SQL code
update a表set b=1where datediff(day,a,getdate())>0
------解决方案--------------------
作业,触发器更新
------解决方案--------------------
update 表a set b=1 where a <getdate()