Does MS SQL Server's “between” include the range boundaries?

前端 未结 8 2162
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 10:53

For instance can

SELECT foo
FROM bar
WHERE foo BETWEEN 5 AND 10

select 5 and 10 or they are excluded from the range?

8条回答
  •  失恋的感觉
    2020-11-27 11:28

    if you hit this, and don't really want to try and handle adding a day in code, then let the DB do it..

    myDate >= '20090101 00:00:00' AND myDate < DATEADD(day,1,'20090101 00:00:00')
    

    If you do include the time portion: make sure it references midnight. Otherwise you can simply omit the time:

    myDate >= '20090101' AND myDate < DATEADD(day,1,'20090101')
    

    and not worry about it.

提交回复
热议问题