Almost does what I want, so I'm playing - cheers!
My structure is such that I have Site records, each of which has a number of child Measuring Device records. Each measuring device receives 96 readings, (numeric scale 8 precision 5), per day taken at 15 minute intervals.
I need to sum each of the measuring devices individual daily period readings to garner a site level daily period reading, excepting that where a measuring device reading is null, the site level aggregate should also be null.
The Site table is the top level, the measuring device table has a foreign key set to the id field of site table, (one to many relationship, site to device), and for each measuring device and day a set of reading records is stored in a reading table with a foreign key to the measuring device table and unique index on measuring device id and date. other than that the reads table has an horrendous 96 read period fields, i.e.,
Site: [SiteId] [Some Other Detail]
Device: [DeviceId] [Some Other Details] [SiteId]
Device Reads: [DeviceId] [Date] [1] [2] .... [96]
so, for all devices belonging to a site, I need to sum the values for each period field, i.e., Sum([1]), Sum[2], etc but again aggregating to NULL where the value for a single device, day and period belonging to a site is NULL.
I'm thinking of tweaking what you've done and simply summing (based on your check for null values) and storing each site, date, period read value in a variable before a simple inserting into my site level reads table which is of the same structure to the device reads table excepting the foreign key is the Site id, (again index on id and date).
Cheers again for pointing my over-tired brain in what seems a logical direction, but hey at least it's friday and i've got the weekend off!
Rhys
"
"Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."
My Home