Using WHERE clause with BETWEEN and null date parameters

前端 未结 6 772

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:20

    How About:

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

提交回复
热议问题