One of my WHERE clauses is the following:
WHERE
AND (DateCreated BETWEEN @DateFrom and @DateTo OR (@DateFrom IS NULL OR @DateTo IS NULL))
Use this where clause
where clause
WHERE ( DateCreated BETWEEN @DateFrom AND @DateTo ) OR ( @DateFrom IS NULL AND @DateTo IS NULL ) OR ( @DateFrom IS NULL AND DateCreated <= @DateTo ) OR ( @DateTo IS NULL AND DateCreated >= @DateFrom )