In the form the user is able to ask for records based on an Age. So 5 days old, 2 days old, etc. The age is based on the date that the record was entered or received. So we have JobReceiveDate.
The stored procedure was written like this. Where @Ageto and @AgeFrom come from the online form.
Expand|Select|Wrap|Line Numbers
- JobReceivedDate Between DateAdd(dd, (isnull(@AgeTo,60000)* -1),JobReceivedDate) AND DateAdd(dd, (isnull(@AgeFrom,0)* -1),JobReceivedDate)
In doing this the query can not use the index on set up for JobReceiveDate.
Can anyone think of a better way to write this code? I can't think of how I could totally remove the function so that the index will be utilized.