Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / April 2007



Tip: Looking for answers? Try searching our database.

stored procedure help - ms sql server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Protoculture - 30 Apr 2007 11:36 GMT
[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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.