Hello, I have a script that is designed to find the most previous TimeAndDate for each record. I need to run this script for thousands and/or millions of DataLoggerKeys. The way the script runs now, it runs out of resources pretty quickly. Can somebody offer a suggestion as to how I can edit the script so that it will iterate over the various DataLoggerKeys? I believe that this it the best way to keep the query from being overloaded. Any other suggestions appreciated to keep the query efficient.
Thanks in advance,
Mike
Thanks in advance,
Mike
Code:
[FONT=Arial][SIZE=2]select target.MemoryDataKey, target.DataLoggerKey, target.DateCreated, target.timeAndDate, target.Occupied, target.Lights, target.Microphone, target.PrimaryKey, max(before.timeAndDate) as previousTimeAndDate into TimeSeriesMDT
from MDT before, MDT target
where before.timeAndDate < target.timeAndDate
and before.DataLoggerKey = target.DataLoggerKey
group by target.MemoryDataKey, target.DataLoggerKey, target.DateCreated, target.timeAndDate, target.Occupied, target.Lights, target.Microphone, target.PrimaryKey
order by target.DataLoggerKey, target.timeAndDate [/SIZE][/FONT]