I am new to having to manage our sqlserver db. got handed this request.
I have a large table with a million records. Would like to run this report. It is taking over an hour using SQL Server 2008.
Rowid is PK and there is an index on dx and varcharfield.
SELECT T1.VarcharField,
T1.DX,
T1.ROWID,
(SELECT Sum(t2.QC) AS Total
FROM tbl t2
WHERE T2.VarcharField = T1.VarcharField
AND t2.dx <= t1.dx) AS Total
FROM tbl AS T1
I think this will run faster: