Simple use of IF inside procedure
Try like this

WHERE....
AND...
AND (x.DATE&gt;= @Startdate OR @Startdate IS NULL)
AND (x.DATE&lt;= @enddate OR @enddate IS NULL)


Possibly with OPTION (RECOMPILE).

See Dynamic Search Conditions in T‑SQL by Erland Sommarskog.