I am learning to use the SQL Server MERGE statement on this page: https://technet.microsoft.com/en-us/library/bb522522(v=sql.105).aspx
MERGE dbo.FactBuyingHabits AS Target
USING (SELECT CustomerID, ProductID, PurchaseDate FROM dbo.Purchases) AS Source
ON (Target.ProductID = Source.ProductID AND Target.CustomerID = Source.CustomerID)
WHEN MATCHED THEN
UPDATE SET Target.LastPurchaseDate = Source.PurchaseDate
WHEN NOT MATCHED BY TARGET THEN
INSERT (CustomerID, ProductID, LastPurchaseDate)
VALUES (Source.CustomerID, Source.ProductID, Source.PurchaseDate)
OUTPUT $action, Inserted.*, Deleted.*;
However, all the examples I can find (like the one above) use the actual table as the source. Is it possible to transfer data directly? I would prefer not to create a temporary table for this (if it is possible and recommended?). How would the request change above?
thank
source
share