首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql 时间的比较,该如何解决

2012-08-25 
sql 时间的比较表A、表B两个表,A表有一个时间字段timeA,B表有两个时间字段time1,time2,ps(这两个时间字段有

sql 时间的比较
表A、表B两个表,A表有一个时间字段timeA,B表有两个时间字段time1,time2, ps(这两个时间字段有可能为NULL) 比较B表的两个时间字段选大的赋值给A表的timeA 求SQL语句

[解决办法]

SQL code
update a set a.timeA=b.timeAfrom ta as a,tb as b where a.关联条件=b.关联条件and not exists(select 1 from tb where 关联条件=b.关联条件 and time1>b.time1)
[解决办法]
update A set timeA = case
when time1 is null then time2
when time2 is null then them1
when time1 < time2 then time2
else time1 end
from A
join B on A.id=B.id -- 假设A,B表以ID关联

[解决办法]
SQL code
update A set timeA = case  when time1 is null then time2  when time2 is null then them1  when time1 < time2 then time2  else time1 endfrom bwhere  A.关联关系=B.关联关系
[解决办法]
SQL code
update A set timeA = case  when time1 is null then time2  when time2 is null then them1  when time1 < time2 then time2  else time1 endfrom bwhere  A.关联关系=B.关联关系 

热点排行