Hi.
I have a query that runs for 2 hours.
Although iterating the tables take seconds.
tblDWSession has 1.5 M lines the other tables are small 50.000 lines top , of course the problem is the calculation( probably the division is killing it, along with the Datediff). I'm just not good at calculation and I don't know how can I make an alternative that is sargable.Code:UPDATE tblDWSession SET FWeek = CASE WHEN DATEDIFF(D, tblSYSCWeeks.CWStartDate, tblDWSession.SDate)/7+1 <= 0 THEN 1 ELSE DATEDIFF(D, tblSYSWeeks.CWStartDate, tblDWSession.SDate)/7+1 END FROM tblDWF, tblSYSWeeks WHERE tblDWF.Code = tblDWSession.Code AND tblDWF.FDate BETWEEN tblSYSWeeks.CWCStartDate AND tblSYSWeeks.CWEndDate AND tblDWSession.IsProcessCompleted = 0 or tblDWSession.FWeek = 0;
Any ideas?
Also I'm guessing since the tblDWSession table has data from 10 years, doing a getdate - 730 will probably reduce the problem?
Thanks.




Reply With Quote