I am an accidental DBA charged with performance tuning a mess of queries (both literal, and figurative).
One pattern we have is to always store Dates as DateTime2(7) regardless whether we need the time portion or not.
When querying these, one "smart" developer created a scalar function DateOnly() and used that everywhere (figuratively). As you know, and I found out recently, scalar functions usually cause a query to stay single threaded, so I've been working to inline the function as a simple cast(dateColumn as Date).
For performance reasons, I suggested converting the columns to just Date for the tables where Time is not important and was met with resistance.
I recently learned (I did mention that I'm an accidental DBA) about computed columns and wonder if maybe that's a good solution? I'm just not sure about any performance relate issues here and was wondering if there is any sort of best practice.
Yes, I googled it, no I didn't find anything. That's why I'm here.
How would you approach the problem, and why?
Persisted Computed Column
Computed Column with Index