June 23, 2005 at 2:04 pm
Isn't that, what I just said ?
* Noel
June 23, 2005 at 2:06 pm
I understood that you suggested to keep the trigger as it was... Sorry for the misunderstading .
June 23, 2005 at 2:08 pm
no prob
* Noel
June 23, 2005 at 5:46 pm
As others have said, you should use the "inserted" table in your trigger - it contains the new rows of data being inserted. Then you could just update the rows in the other tables that are necessary. Also, this code
UPDATE tblForecastTemp SET hour1 = (SELECT tbltemp.hour1 FROM tbltemp
WHERE tblForecastTemp.[year] = tbltemp.[year] AND tblForecastTemp.[month]
= tbltemp.[month] AND tblForecastTemp.[day] = tbltemp.[day])
WHERE EXISTS (SELECT tbltemp.hour1 FROM tbltemp
WHERE tblForecastTemp.[year] = tbltemp.[year] AND tblForecastTemp.[month]
= tbltemp.[month] AND tblForecastTemp.[day] = tbltemp.[day]);
Could be rewritten using an inner join which might help the query optimiser significantly.
Similarly,
INSERT INTO tblForecastTemp ([year],[month],[day],hour1,hour2,hour3,hour4,hour5,
hour6,hour7,hour8,hour9,hour10,hour11,hour12,hour13,hour14,hour15,hour16,hour17,hour18,hour19,hour20,hour21,hour22,hour23,hour24)
SELECT [year],[month],[day],hour1,hour2,hour3,hour4,hour5,
hour6,hour7,hour8,hour9,hour10,hour11,hour12,hour13,hour14,hour15,hour16,hour17,hour18,hour19,hour20,hour21,hour22,hour23,hour24
FROM ForecastTemp WHERE dbo.dateserial([year],[month],[day]) >
(SELECT TOP 1 dbo.dateserial([year], [month], [day]) FROM tblforecasttemp
ORDER BY dbo.dateserial([year], [month], [day]) DESC)
ORDER BY dbo.dateserial([year],[month],[day])
It looks like you are trying to get the most recent record inserted (based on the last code with the > operator) - again, this is the sort of stuff that you can get from the "inserted" table to speed things up an awful lot.
Cheers
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply