标签:
Values子句不仅能为Insert into子句提供插入的数据源,而且还能作为From子句和Merge中的Using的数据源。
1,Specifying multiple values as a derived table in a FROM clause.
SELECT a, b FROM (VALUES (1, 2), (3, 4), (5, 6), (7, 8), (9, 10) ) AS MyTable(a, b); GO -- Used in an inner join to specify values to return. SELECT ProductID, a.Name, Color FROM Production.Product AS a INNER JOIN (VALUES (‘Blade‘), (‘Crown Race‘), (‘AWC Logo Cap‘)) AS b(Name) ON a.Name = b.Name;
2,Specifying multiple values as a derived source table in a MERGE statement
MERGE INTO Sales.SalesReason AS Target USING (VALUES (‘Recommendation‘,‘Other‘), (‘Review‘, ‘Marketing‘), (‘Internet‘, ‘Promotion‘)) AS Source (NewName, NewReasonType) ON Target.Name = Source.NewName WHEN MATCHED THEN UPDATE SET ReasonType = Source.NewReasonType WHEN NOT MATCHED BY TARGET THEN INSERT (Name, ReasonType) VALUES (NewName, NewReasonType) WHEN NOT MATCHED BY SOURCE THEN DELETE OUTPUT $action;
参照MSDN
Table Value Constructor
https://msdn.microsoft.com/en-us/library/dd776382%28v=sql.110%29.aspx?f=255&MSPPError=-2147217396
Tsql Values子句作为Table Value Constructor
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/4820151.html