SQL判断语句的用法

dickens123456 2010-02-02 11:35:09
有2个datetime类型的属性time1,time2,还有一个属性distance,如果time2-time1的值大于15则修改distance的值为1,这个怎么写呢?
...全文
137 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
丰云 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 dickens123456 的回复:]
有2个datetime类型的属性time1,time2,还有一个属性distance,如果time2-time1的值大于15则修改distance的值为1,这个怎么写呢?

[/Quote]
什么大于15??
年?月?日?小时?。。。。
说清楚嘛
-狙击手- 2010-02-02
  • 打赏
  • 举报
回复
update tb
set distance=1
where time1-time2>15
andysun88 2010-02-02
  • 打赏
  • 举报
回复

update tb
set distance=15
--天
where datediff(dd,time1,time2)>15
--小时
or datediff(hh,time1,time2)>15
--分钟
or datediff(mm,time1,time2)>15
--。。。。。
ws_hgo 2010-02-02
  • 打赏
  • 举报
回复
4楼错误
参考6楼
ws_hgo 2010-02-02
  • 打赏
  • 举报
回复
update tb set distance=(case when datediff(day,time1,time2)>15 then 1 else distance end)
--小F-- 2010-02-02
  • 打赏
  • 举报
回复
update
tb
set
distance=1
where
time2-time1>15
ws_hgo 2010-02-02
  • 打赏
  • 举报
回复
update tb set distance=(case when time2-time1>15 then 1 else distance end)
黄_瓜 2010-02-02
  • 打赏
  • 举报
回复
select distance=case when datediff(dd,time1,time2)>15 then 1 else distance end 
from tb
andysun88 2010-02-02
  • 打赏
  • 举报
回复
15是什么类型【时,分,秒。。。】
sgtzzc 2010-02-02
  • 打赏
  • 举报
回复
update tb
set distance=1
where datediff(dd,time1,time2)>15


如果time2-time1的值大于15

--是指天数吗

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧