I have a SELECT statement with 2 conditions in the WHERE clause and I want 1 of those conditions to be optional as the value may or may not be passed in by the calling application. Doing some goggling I found this solution:
WHERE di.InventoryDate BETWEEN @SDate AND @EDate
AND di.JDELocation = @JDELocation OR @JDELocation IS NULL
Which works, sort of. As long as the JDELocation is passed in the results returned will always be between the Sdate and EDate but if the JDELocation is not passed in by the calling app then the date constraint is ignored. How can I modify this so that even if the JDELocation is not passed in the date constraint is still followed?
If I get used to envying others...
Those things about my self I pride will slowly fade away.