Does BETWEEN with dates actually work in SQL SERVER 2008

后端 未结 8 956
旧时难觅i
旧时难觅i 2021-01-20 00:36

According to cdonner, in his answer here and on his blog.

He claims that BETWEEN with date yields inconsistent results

From his blog:

<
8条回答
  •  孤独总比滥情好
    2021-01-20 00:56

    I have to use something like this:

    Declare @BeginDate SmallDateTime
    Declare @EndDate SmallDateTime
    Set @BeginDate = '2007-08-01'
    Set @EndDate = '2007-08-31'
    
    Select *
    From dbo.table1 a
    Where a.session_date Between @BeginDate + ' 00:00:00' And @EndDate + ' 23:59:59'
    Order By a.session_date asc
    

    To get correct BETWEEN datetime's

提交回复
热议问题