Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optimisation of sum queries

Status
Not open for further replies.

simon43

Programmer
Aug 5, 2004
1
GB
Hi

I am struggling to try an opimise two queries and am not sure that there is any obvious way, can anybody help?

Many thanks

Simon


SELECT
SUM(B.Length) AS [Length_Poor]
FROM
tbl_Residual_Life_Sections_Run AS A
INNER JOIN
tbl_Residual_Life_Readings_Run AS B
ON
A.ID = B.Section_ID
WHERE
A.Section NOT IN (SELECT Section FROM tbl_Schemes_Run WHERE Year = 2004)
AND NOT B.Long_Life AND B.[2004] <= 0 AND A.Start_Year <= 2004
AND A.End_Year > 2004

Set recData = pdtbUser.OpenRecordset(strSQL, dbOpenSnapshot)

lngResidualLifeLength = IIf(IsNull(recData.Fields("Length_Poor")), 0, recData.Fields("Length_Poor"))



SELECT
SUM(Length) AS [Length_Poor]
FROM
tbl_Rutting_Sections_Run AS A
INNER JOIN
tbl_Rutting_Readings_Run AS B
ON
A.ID = B.Section_ID
WHERE
A.Section NOT IN (SELECT Section FROM tbl_Schemes_Run WHERE Year = 2004)
AND
B.[2004] <= B.Investigatory_Level
AND
A.Start_Year <= 2004
AND
A.End_Year > 2004

Set recData = pdtbUser.OpenRecordset(strSQL, dbOpenSnapshot)

lngRuttingLength = IIf(IsNull(recData.Fields("Length_Poor")), 0, recData.Fields("Length_Poor"))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top