Does BETWEEN with dates actually work in SQL SERVER 2008

后端 未结 8 900
旧时难觅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 01:08

    The code on the blog was nonsense, and I owe Mark for pointing that out to me. The issue exists. It has nothing to do with BETWEEN, but with rounding (which can cause BETWEEN to fail in certain circumstances). While SQL Server does round, .Net does not, and I ran into issues with multiple inserts in a very short timeframe where I assumed that I had distinct datetime values, but due to rounding they became the same in the database. The post was corrected a long time ago, and the code examples still work on SQL Server 2008.

    If you run this query, you will see what I was referring to:

    select convert(varchar(32), convert(datetime,
                                '9/1/08 00:00:00.005'), 121);
    

提交回复
热议问题