I have the following query, and because of a lot of SUM function calls, my query is running too slow. I have a lot of records in my database and I would like to get
SUM
Just use computed colums
Example
ALTER TABLE tb1 ADD [Current - Last 30 Days Col1] AS (CASE WHEN a.DateCol >= DATEADD(MONTH,-1,GETDATE()) THEN a.col1 ELSE 0 END) PERSISTED;
Specify Computed Columns in a Table