Re: Query taking too long
From: Ravi (Ravi_at_discussions.microsoft.com)
Date: 01/03/05
- Next message: Seth Schwarm: "InStrRev not working"
- Previous message: Karen Middleton: "How to read a table record by record and process and update another table"
- In reply to: John Vinson: "Re: Query taking too long"
- Next in thread: John Spencer (MVP): "Re: Query taking too long"
- Reply: John Spencer (MVP): "Re: Query taking too long"
- Reply: Ted Allen: "Re: Query taking too long"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 2 Jan 2005 20:57:16 -0800
Hi
Table:
VehicleID....VehId
Log Date.....Dt...Date/time
Mileage......Mile..Number
Then i use a query to group vehiclewise
SELECT Table1.VehID, Min(Table1.Dt) AS MinDt, Max(Table1.Dt) AS MaxDt,
Max(Table1.Mile) AS MaxMiles
FROM Table1
GROUP BY Table1.VehID;
The query below is then used for finding the average:
**Countworkdays(startdate,EndDate)...vb function to count the work days
SELECT Avg1qry.VehID, Avg1qry.MaxDt, Avg1qry.MinDt, Avg1qry.MaxMiles,
(CountWorkDays([MinDt],[MaxDt])) AS WkDay, ([MaxMiles]/[WkDay]) AS Average
FROM Avg1qry;
When i run this query..for just 2 records which are 5 yrs old..i.e
startDate= 01/01/2000 and Enddate=31/12/2004..it takes 8 seconds
Ravi
"John Vinson" wrote:
> On Sun, 2 Jan 2005 14:15:02 -0800, "Ravi"
> <Ravi@discussions.microsoft.com> wrote:
>
> >Hi
> >I are trying to get the average consumption of our vehicles.
> >A log is entered every 2 days with "Log Date" and Mileage
> >In a query for number of days i take MaxDate-MinDate and count 'only' the
> >working days for which a vb function is used
> >
> >When the query is run ...it takes too much time since it is calculating the
> >'working days' for each vehicle..the records go back 5 years so it calculates
> >from Date() to 5 years.
> >I feel the approach i am using is not very efficient.
> >Please give me an idea how to speed up the query
> >Thanks
> >Ravi
>
> Please post a description of your table, and the SQL view of your
> current query. Calling a VBA function for every row in a query is
> indeed going to be a major performance drag.
>
>
> John W. Vinson[MVP]
>
- Next message: Seth Schwarm: "InStrRev not working"
- Previous message: Karen Middleton: "How to read a table record by record and process and update another table"
- In reply to: John Vinson: "Re: Query taking too long"
- Next in thread: John Spencer (MVP): "Re: Query taking too long"
- Reply: John Spencer (MVP): "Re: Query taking too long"
- Reply: Ted Allen: "Re: Query taking too long"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|