ここでは、あなたのクエリを実行します。
は影響を受け
update dashboardtasks1 set
tasktype = s.tasktype,
[desc] = s.[desc],
duedate = s.duedate,
compdate = s.compdate,
comments = s.comments,
agent = s.agent,
compby = s.compby,
graceperiod = s.graceperiod
from staggingtasks as s
where
s.tour=dashboardtasks1.tour and
s.taskname=dashboardtasks1.taskname and
s.deptdate=dashboardtasks1.deptdate
四行UPDATE文のテストデータ
create table dashboardtasks1(id int identity, tour int, taskname nvarchar(50), deptdate datetime, tasktype nvarchar(50), [desc] nvarchar(50), duedate datetime, compdate datetime, comments nvarchar(50), agent nvarchar(50), compby int, graceperiod int)
create table staggingtasks(id int, tour int, taskname nvarchar(50), deptdate datetime, tasktype nvarchar(50), [desc] nvarchar(50), duedate datetime, compdate datetime, comments nvarchar(50), agent nvarchar(50), compby int, graceperiod int)
insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (62, 3647, 'Request Space', '2011-03-30', 'Land', NULL, '2010-01-06', NULL, NULL, 'PEGGYH', NULL, NULL)
insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (81, 505, 'Rel. Space', '2012-02-22', 'Land', NULL, '2011-12-24', NULL, NULL, 'IMANA', NULL, NULL)
insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (82, 505, 'Ticket', '2012-02-22', 'Air', NULL, '2012-01-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (83, 505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-01-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (90, 505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-01-01', NULL, NULL, 'SYLVIAT', NULL, NULL)
insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (92, 505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-01-01', NULL, NULL, 'SYLVIAT', NULL, NULL)
insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (3647, 'Request Space', '2011-03-30', 'Land', NULL, '2010-11-06', NULL, NULL, 'PEGGYH', NULL, NULL)
insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (505, 'Rel. Space', '2012-02-22', 'Land', NULL, '2011-11-24', NULL, NULL, 'IMANA', NULL, NULL)
insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (505, 'Ticket', '2012-02-22', 'Air', NULL, '2012-11-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
values (505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-11-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
実行]を設定します。 dashboardtasks1からの選択は、あなたの
id tour taskname deptdate tasktype desc duedate compdate comments agent compby graceperiod
1 3647 Request Space 2011-03-30 00:00:00.000 Land NULL 2010-01-06 00:00:00.000 NULL NULL PEGGYH NULL NULL
2 505 Rel. Space 2012-02-22 00:00:00.000 Land NULL 2011-12-24 00:00:00.000 NULL NULL IMANA NULL NULL
3 505 Ticket 2012-02-22 00:00:00.000 Air NULL 2012-01-08 00:00:00.000 NULL NULL SYLVIAT NULL NULL
4 505 Names to Airlines 2012-02-22 00:00:00.000 Air NULL 2012-01-08 00:00:00.000 NULL NULL SYLVIAT NULL NULL
が
insert into dashboardtasks1 (tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
select tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod
from staggingtasks as s
where not exists (select *
from dashboardtasks1 as d
where s.tour=d.tour and
s.taskname=d.taskname and
s.deptdate=d.deptdate and
s.duedate=d.duedate
)
2つの行が影響を受けているinsert文を実行し、この結果を与えます。 dashboardtasks1に対するクエリでは、この結果が得られます。
id tour taskname deptdate tasktype desc duedate compdate comments agent compby graceperiod
1 3647 Request Space 2011-03-30 00:00:00.000 Land NULL 2010-01-06 00:00:00.000 NULL NULL PEGGYH NULL NULL
2 505 Rel. Space 2012-02-22 00:00:00.000 Land NULL 2011-12-24 00:00:00.000 NULL NULL IMANA NULL NULL
3 505 Ticket 2012-02-22 00:00:00.000 Air NULL 2012-01-08 00:00:00.000 NULL NULL SYLVIAT NULL NULL
4 505 Names to Airlines 2012-02-22 00:00:00.000 Air NULL 2012-01-08 00:00:00.000 NULL NULL SYLVIAT NULL NULL
5 505 Names to Airlines 2012-02-22 00:00:00.000 Air NULL 2012-01-01 00:00:00.000 NULL NULL SYLVIAT NULL NULL
6 505 Names to Airlines 2012-02-22 00:00:00.000 Air NULL 2012-01-01 00:00:00.000 NULL NULL SYLVIAT NULL NULL
これは予想される動作/結果ですか?
ちょうどニトピックとして:あなたが使っているのは「ステージング」テーブルと呼ばれるでしょう。 –
ありがとうございました。それを修正する必要があります – MyHeadHurts