(1) Will you ever be inserting records unrelated to the previous minute or does it just need to look at the previous minute? (2) Why insert all these different records at all? Can you not just do an upsert using merge so it will only insert if there is no record for that minute and otherwise increment it?
–
Martin SmithOct 8 '10 at 15:09

This is for the graphing of values. When looking at the live chart, values are broken down into 10 second intervals. After a minute has elpased, the values are consolidated. After an hour, the minutes are consolidated, etc.
–
George JohnstonOct 8 '10 at 15:16

The way the script works is that, within a transaction, it updates Value for the '00' time by summing up all the values for that minute IF there is at least two records for that minute range (i.e. 00 seconds, 10 seconds) so that unnecessary updates aren't performed.

The query then deletes all records that don't have '00' for seconds, as they will all have been included in the update above.