ROM句を使ったUPDATE statementのサンプル

USE AdventureWorks2012;
GO
CREATE TABLE dbo.Table1 (ColA int NOT NULL, ColB decimal(10,3) NOT NULL);
GO
CREATE TABLE dbo.Table2 (ColA int PRIMARY KEY NOT NULL, ColB decimal(10,3) NOT NULL);
GO
INSERT INTO dbo.Table1 VALUES(1, 10.0), (1, 20.0);
INSERT INTO dbo.Table2 VALUES(1, 0.0);
GO
UPDATE Table2 SET
  ColB = T2.ColB + T1.ColB
FROM Table2 T2
  INNER JOIN Table1 T1
    ON (T2.ColA = T1.ColA);
GO
SELECT ColA, ColB FROM dbo.Table2;

 

https://technet.microsoft.com/ja-jp/library/ms177523(v=sql.110).aspx より

 

広告を非表示にする