[1] basically I need to select certain rows from the db and grab their IDs... (
done)
[2] now I have to perform a series of insert statments based on those ids
retrieved.
I thought about storing the results of [1] into a table variable and then
looping over that variable to perform my insert statments...
how can this be done?
DECLARE @timeoutDays_Green int
DECLARE @timeoutDays_Amber int
SET @timeoutDays_Green = (SELECT timeoutDays FROM dbo.time_trk_color_codes
WHERE id = 1)
SET @timeoutDays_Amber = (SELECT timeoutDays FROM dbo.time_trk_color_codes
WHERE id = 2)
DECLARE @todayDate dateTime
SET @todayDate = getDate()
DECLARE @historyItemDate dateTime
SELECT
hist.id AS 'hist_id',
@timeoutDays_Green AS 'TOUT'
FROM
time_trk_history hist,
time_trk_items items
WHERE
dbo.GetWorkingDays(cast(hist.dateTimeStart as smalldatetime), cast(@todayDate
as smalldatetime) ) > @timeoutDays_Green
AND
hist.status_to_colorID = 1
-- INSERT NEW RECORDS, USING THE ID GAINED FROM THE QUERY ( IE OUTDATED ITEMS )
INSERT INTO
time_trk_history
(
caseID, dateCreated, status_to_colorID, dateTimeStart, commentID
)
VALUES
(
)
paross1 - 30 Apr 2007 15:23 GMT
Your insert doesn't specify which previously selected values match up with
which columns in the inteded insert table time_trk_history so it is hard to
recommend more than a hypothecical. Having said that, why don't you move your
SELECT statment into your INSERT statement:
INSERT INTO
time_trk_history
(caseID, dateCreated, status_to_colorID, dateTimeStart, commentID)
SELECT whatever columns and constants that you want
FROM time_trk_history hist, time_trk_items items
WHERE whatever.....
Phil