by HansV » 18 May 2010, 14:23
As far as I can tell, the IIf's aren't necessary. The result of DCount will always be a number >= 0, so the Else part of IIf will never be used. And In (3, 4) is probably a bit more efficient than Between 3 and 4. This means that you can reduce the SQL to
UPDATE tblReportLagTimeDept SET tblReportLagTimeDept.LAG_numCurrMnth3 = DCount("pkey","7sqCY_WCReported","DeptCategory = " & Chr(34) & [Dept Category ] & Chr(34) & "and loc_lvl2_t=" & Chr(34) & [LAG_ProfitCenter] & Chr(34) & "AND [intDayToReport] In (3, 4) AND Month([occur_rdate])=Month([Forms]![frmReportSelection]![txtEndDate])"), tblReportLagTimeDept.LAG_numCurrMnth5 = DCount("pkey","7sqCY_WCReported","DeptCategory = " & Chr(34) & [Dept Category ] & Chr(34) & "and loc_lvl2_t=" & Chr(34) & [LAG_ProfitCenter] & Chr(34) & "AND [intDayToReport] > 4 AND Month([occur_rdate])=Month([Forms]![frmReportSelection]![txtEndDate])"), tblReportLagTimeDept.LAG_numPYYTD1 = DCount("pkey","1sqClaimsReportedPY","DeptCategory = " & Chr(34) & [Dept Category ] & Chr(34) & "and loc_lvl2_t=" & Chr(34) & [LAG_ProfitCenter] & Chr(34) & "AND [intDayToReport] <3 AND [cov_major]='WC'"), tblReportLagTimeDept.LAG_numPYYTD3 = DCount("pkey","1sqClaimsReportedPY","DeptCategory = " & Chr(34) & [Dept Category ] & Chr(34) & "and loc_lvl2_t=" & Chr(34) & [LAG_ProfitCenter] & Chr(34) & "AND [intDayToReport] In (3, 4) AND [cov_major]='WC'");
It might be possible to simplify the query further, but I'd need to see the database to know for sure.
Regards,
Hans