SQL Server和日期+ 1个结果 [英] SQL Server and date + 1 result

查看:163
本文介绍了SQL Server和日期+ 1个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于SQL Server。说,如果我有一个带有[myDate]列的表,该表的类型为datetime,那么在以下情况下向其添加1意味着什么?

In case of the SQL Server. Say, if I have a table with [myDate] column that is of the type datetime, what would adding 1 to it mean in the following context?

SELECT * 
  FROM [myTable] 
 WHERE [myDate] + 1 > @someDate


推荐答案

添加一天(恰好是24小时)

It adds one day (exactly 24 hours)

但是,您的查询通过这种方式更加正确。如果该列中有一个,则该列上的函数或处理通常会使索引使用无效

However, your query is more correct this way. The function or processing on the column usually invalidates index usage if there is one of that column

WHERE [myDate] > @someDate - 1

OR

WHERE [myDate] > DATEADD(day, -1, @someDate)

这篇关于SQL Server和日期+ 1个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆