サンプルデータ:
create table Table1 (KeyField int,FieldName varchar(20),Targetcolumntoupdate numeric(5,2));
create table Table2 (KeyField int,FieldName varchar(20),Sourcecolumntoupdate numeric(5,2));
insert into Table1 values (1,'F1',0.00);
insert into Table1 values (2,'F1',0.00);
insert into Table2 values (1,'F1',1.00);
insert into Table2 values (1,'F1',2.00);
Table1 の列を次のように更新しようとしていますか?
-- Wrong approach possible cause of error stated
Update Table1
Set Table1.Targetcolumntoupdate =
( SELECT (T2.Sourcecolumntoupdate)
FROM Table1 T1
INNER JOIN Table2 T2 ON
T1.KeyField = T2.KeyField AND T1.FieldName = T2.FieldName) ;
Targetcolumntoupdate を更新するために必要なデータを選択するために作成したサブクエリが複数の可能な値を返すことがわかります。
正しいクエリは次のとおりです。
Update T1
Set T1.Targetcolumntoupdate = (T2.Sourcecolumntoupdate)
FROM Table1 T1
INNER JOIN Table2 T2 ON
T1.KeyField = T2.KeyField AND T1.FieldName = T2.FieldName;
お役に立てれば!!!