Even without your problem, your query is badly constructed and will be slooow on a production server storing a few years of history.
You are using
getdate()
in the
when
clause, the problem is that the function is volatile, its value changes any time you call it.
This mean that the server can't optimize the filter and the workload depend on the number of records in the table. The fact that you are butchering date fields is another reason to not optimize, because it is beyond the understanding of the server.
The other way to do it is to compute a StartDate and EndDate of records you want
before the
select.
And then :
when OCSBillDate between @StartDate and @EndDate
This way, the SQL server knows how to take advantage of an index, and the workload will depend on the number of records matching the constraint.