下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
USE AdventureWorks2012;GOCREATE table Production.UpdatedInventory (ProductID INT NOT NulL,LocationID int,NewQty int,PrevIoUsQty int,CONSTRAINT PK_Inventory PRIMARY KEY CLUSTERED (ProductID,LocationID));GOINSERT INTO Production.UpdatedInventorySELECT ProductID,LocationID,NewQty,PrevIoUsQty FROM( MERGE Production.ProductInventory AS pi USING (SELECT ProductID,SUM(OrderQty) FROM Sales.SalesOrderDetail AS sod JOIN Sales.SalesOrderheader AS soh ON sod.SalesOrderID = soh.SalesOrderID AND soh.OrderDate BETWEEN '20030701' AND '20030731' GROUP BY ProductID) AS src (ProductID,OrderQty) ON pi.ProductID = src.ProductID WHEN MATCHED AND pi.Quantity - src.OrderQty >= 0 THEN UPDATE SET pi.Quantity = pi.Quantity - src.OrderQty WHEN MATCHED AND pi.Quantity - src.OrderQty <= 0 THEN DELETE OUTPUT $action,Inserted.ProductID,Inserted.LocationID,Inserted.Quantity AS NewQty,Deleted.Quantity AS PrevIoUsQty) AS Changes (Action,ProductID,PrevIoUsQty) WHERE Action = 'UPDATE';GO
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的将 MERGE 语句的执行结果插入到另一个表中全部内容,希望文章能够帮你解决将 MERGE 语句的执行结果插入到另一个表中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)