I will be receiving a list of 250+ Agent IDs from a superior. They will all be input into tblAgentVisitLoad, which is a single column table (AgtID).
I want to take each AgtID in tblAgentVisitLoad and run the following query on them. I have comments within the query on where the loop is to be placed.
DECLARE @varVisit Table (id int)
DECLARE @varVisitID Int
DECLARE @varDate DateTime
DECLARE @varCreated Int
DECLARE @varAssigned Int
DECLARE @varAgtID Int
Set @varDate = '3/31/2015' -- This is the DEADLINE DATE to change quarterly
Set @varCreated = 193 -- Created By ID
Set @varAssigned = 194 -- Assigned staff member ID
-- For each value in tblAgentVisitLoad
Set @varAgtID = tblAgentVisitLoad.AgtID -- This will be what is dynamically set
INSERT INTO tblAgentVisit (StatusID, DeadlineDate, Objective, ScheduledDate, Location, Summary, Created_user_id, assignedStaff)
OUTPUT Inserted.VisitID INTO @varVisit
VALUES
(1 --Scheduled
,@varDate
,''
,''
,''
,''
,@varCreated
,@varAssigned)
Set @varVisitID = (Select Id from @varVisit)
INSERT INTO tblAgentVisitAgents (VisitID, AgtID, Prime, Interests, referred, years, bussize)
VALUES
(@varVisitID
,@varAgtID -- This is where the loop will need to be entered
,1
,''
,''
,''
,'')
I'm not sure if there's a FOR EACH loop I can use here, or if CURSOR is my best bet. Can anyone assist me?
Aucun commentaire:
Enregistrer un commentaire