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

前端 未结 8 2181
佛祖请我去吃肉
佛祖请我去吃肉 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:40

    Real world example from SQL Server 2008.

    Source data:

    ID    Start
    1     2010-04-30 00:00:01.000
    2     2010-04-02 00:00:00.000
    3     2010-05-01 00:00:00.000
    4     2010-07-31 00:00:00.000
    

    Query:

    SELECT
        *
    FROM
        tbl
    WHERE
        Start BETWEEN '2010-04-01 00:00:00' AND '2010-05-01 00:00:00'
    

    Results:

    ID    Start
    1     2010-04-30 00:00:01.000
    2     2010-04-02 00:00:00.000
    

    alt text

提交回复
热议问题