Does BETWEEN with dates actually work in SQL SERVER 2008

后端 未结 8 906
旧时难觅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:13

    Very useful discussion!

    I had similar issues, resolved by using CAST and CONVERT, as in:

    cast(CONVERT(varchar(8), [PostDate], 112)AS DATE) BETWEEN '2013-01-01' AND '2013-01-31'

    Works like a charm, as verified with multiple detailed validations.

    The "Cast(" is required (believe me, I have the bald spots to prove it). But didn't have to declare variables, etc.

    Would be interested in feedback, if I'm missing the boat with the method or my response.

    Thanks!

提交回复
热议问题