December 2, 2009 at 9:38 am
Essentially want to insert/update rows from tasks table to tasksimport.
MERGE TASKSIMPORT as Target
USING (select HostName, TaskName, Next_Run_Time, Status, Logon_Mode, Last_Run_Time,
Last_Result, Creator, Schedule, Task_To_Run, Start_In, Comment, Scheduled_Task_State,
Scheduled_Type, Start_Time, Start_Date, End_Date, Days, Months, Run_As_User,
Delete_Task_If_Not_Rescheduled, Stop_Task_If_Runs_X_Hours_and_X_Mins, Repeat_Every,
Repeat_Until_Time, Repeat_Until_Duration, Repeat_Stop_If_Still_Running, Idle_Time,
Power_Management from tasks)
AS source (HostName, TaskName, Next_Run_Time, Status, Logon_Mode, Last_Run_Time,
Last_Result, Creator, Schedule, Task_To_Run, Start_In, Comment, Scheduled_Task_State,
Scheduled_Type, Start_Time, Start_Date, End_Date, Days, Months, Run_As_User,
Delete_Task_If_Not_Rescheduled, Stop_Task_If_Runs_X_Hours_and_X_Mins, Repeat_Every,
Repeat_Until_Time, Repeat_Until_Duration, Repeat_Stop_If_Still_Running, Idle_Time,
Power_Management)
on (target.hostname = source.hostname AND target.taskname = source.taskname)
WHEN MATCHED THEN
UPDATE set Next_Run_time = source.Next_Run_Time, Status = source.Status, Logon_Mode = source.Logon_Mode,
Last_run_time = source.Last_Run_Time, Last_Result = source.Last_Result,
Creator = source.Creator, Schedule = source.Schedule, Task_To_Run = source.Task_To_Run,
Start_in = source.Start_In, Comment = source.Comment, Scheduled_Task_State = source.Scheduled_Task_State,
Scheduled_Type = source.Scheduled_Type, Start_Time = source.Start_Time,
Start_Date = source.Start_Date, End_Date source.End_Date, Days = source.Days,
Months = source.Months, Run_As_User = source.Run_As_User,
Delete_Task_If_Not_Rescheduled = source.Delete_Task_If_Not_Rescheduled,
Stop_Task_if_Runs_X_Hours_and_X_Mins = source.Stop_Task_If_Runs_X_Hours_and_X_Mins,
Repeat_Every = source.Repeat_Every, Repeat_Until = source.Repeat_Until_Time,
Repeat_Until_Duration = source.Repeat_Until_Duration,
Repeat_Stop_If_Still_running = source.Repeat_Stop_If_Still_Running,
Idle_Time = source.Idle_Time, Power_Management = source.Power_Management
WHEN NOT MATCHED THEN
INSERT ([HostName], [TaskName], [Next_Run_Time], [Status], [Logon_Mode], [Last_Run_Time], [Last_Result],
[Creator], [Schedule], [Task_To_Run], [Start_In], [Comment], [Scheduled_Task_State], [Scheduled_Type],
[Start_Time], [Start_Date], [End_Date], [Days], [Months], [Run_As_User], [Delete_Task_If_Not_Rescheduled],
[Stop_Task_If_Runs_X_Hours_and_X_Mins], [Repeat_Every], [Repeat_Until_Time], [Repeat_Until_Duration],
[Repeat_Stop_If_Still_Running], [Idle_Time], [Power_Management])
VALUES (source.HostName, source.TaskName, source.Next_Run_Time, source.Status, source.Logon_Mode, source.Last_Run_Time, source.Last_Result,
source.Creator, source.Schedule, source.Task_To_Run, source.Start_In, source.Comment, source.Scheduled_Task_State, source.Scheduled_Type,
source.Start_Time, source.Start_Date, source.End_Date, source.Days, source.Months, source.Run_As_User, source.Delete_Task_If_Not_Rescheduled,
source.Stop_Task_If_Runs_X_Hours_and_X_Mins, source.Repeat_Every, source.Repeat_Until_Time, source.Repeat_Until_Duration,
source.Repeat_Stop_If_Still_Running, source.Idle_Time, source.Power_Management)
I am getting these errors:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.
Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'AS'.
December 2, 2009 at 11:58 am
You might get better response for this question in the SQL Server 2008 forums.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply