Alternatively, you cannot restrict to the date parameter if it is NULL :
SELECT * FROM ArCustomer ac WHERE CAST(ac.Customer as int) > 1000 AND (ac.DateLastSale >= @StartDate OR @StartDate IS NULL) AND (ac.DateLastSale <= @EndDate OR @EndDate IS NULL)
Or ... you can handle NULL by treating it as the bottom or end date:
SELECT * FROM ArCustomer ac WHERE CAST(ac.Customer as int) > 1000 AND ac.DateLastSale BETWEEN ISNULL(@StartDate, '1900-01-01') AND ISNULL(@EndDate, '9999-12-31')
EDIT:
There may be a difference in execution plan between the two approaches, so you can try both methods and see if one of the others will execute ...
source share