C
Codemonkey
Hi,
I have a table laid out with the following structure:
SampleDate (DateTime),
Value (Long Integer)
Both fields are cumalitive (i.e. Each sucessive sample date is later than
the previous record and each value field is greater than the last).
The amount of time between each record is not constant (a sample may be
taken every 10 minutes or at different varying intervals).
What is the easiest and most efficient way of grouping these records by a
configurable time period? For example to:
1) Get the Max of Value for each hour in the day or each day in the month or
each month in the year?
2) Get the Change (Max-Min) of Value for each hour in the day or each day in
the month or each month in the year?
Obviously no record should be returned for a time period where there is no
sample. I also want to use SQL only (so it can be called from ADO.net).
At the minute, I'm grouping on the following Calculated Field:
Format(SampleDate, "dd/MM/yyyy HH")
This results in grouping the records for each hour in the day. I don't like
this method for the following reasons:
1) The performace could be better without the changing from Date to String.
2) I'm stuck with time periods defined by the different format strings that
Format() can accept - e.g. I can't break it down in to 6 hour periods.
Any ideas would be greatly appreciated, I'm open to suggentions on queries
and table design (or anything else that may help!)
Thanks,
Trev.
I have a table laid out with the following structure:
SampleDate (DateTime),
Value (Long Integer)
Both fields are cumalitive (i.e. Each sucessive sample date is later than
the previous record and each value field is greater than the last).
The amount of time between each record is not constant (a sample may be
taken every 10 minutes or at different varying intervals).
What is the easiest and most efficient way of grouping these records by a
configurable time period? For example to:
1) Get the Max of Value for each hour in the day or each day in the month or
each month in the year?
2) Get the Change (Max-Min) of Value for each hour in the day or each day in
the month or each month in the year?
Obviously no record should be returned for a time period where there is no
sample. I also want to use SQL only (so it can be called from ADO.net).
At the minute, I'm grouping on the following Calculated Field:
Format(SampleDate, "dd/MM/yyyy HH")
This results in grouping the records for each hour in the day. I don't like
this method for the following reasons:
1) The performace could be better without the changing from Date to String.
2) I'm stuck with time periods defined by the different format strings that
Format() can accept - e.g. I can't break it down in to 6 hour periods.
Any ideas would be greatly appreciated, I'm open to suggentions on queries
and table design (or anything else that may help!)
Thanks,
Trev.