Using WHERE clause with BETWEEN and null date parameters

前端 未结 6 810

One of my WHERE clauses is the following:

AND (DateCreated BETWEEN @DateFrom and @DateTo OR (@DateFrom IS NULL OR @DateTo IS NULL))
6条回答
  •  一个人的身影
    2021-01-04 01:13

    This can simply be done by using ISNULL function.

    DateCreated BETWEEN ISNULL(@DateFrom,DateCreated) AND ISNULL(@DateTo,DateCreated)
    

提交回复
热议问题