SQL Server中Merge的用法

来源:互联网 发布:php网站开发实例 编辑:程序博客网 时间:2024/05/17 22:52

SET IDENTITY_INSERT m2c_final.dbo.m2c_SOM_Order_Items ON ;
MERGE m2c_final.dbo.m2c_SOM_Order_Items AS Target
USING (SELECT * from m2c_shadow.dbo.m2c_SOM_Order_Items ) AS Source
ON (Target.AutoId = Source.AutoId)
WHEN MATCHED THEN
   UPDATE  SET
 Target.[Order_Id] = Source.[Order_Id]
, Target.[Goods_Id] = Source.[Goods_Id]
, Target.[CusGoods_Id] = Source.[CusGoods_Id]
, Target.[Goods_Name] = Source.[Goods_Name]
, Target.[Goods_Color] = Source.[Goods_Color]
, Target.[Goods_Spec] = Source.[Goods_Spec]
, Target.[Qty] = Source.[Qty]
, Target.[Unit] = Source.[Unit]
, Target.[Price] = Source.[Price]
, Target.[Amount] = Source.[Amount]
, Target.[Maker] = Source.[Maker]
, Target.[MakeDate] = Source.[MakeDate]
, Target.[Remark] = Source.[Remark]
, Target.[Base_Price] = Source.[Base_Price]
, Target.[Item_Mark] = Source.[Item_Mark]
, Target.[Weight] = Source.[Weight]
, Target.[Pic] = Source.[Pic]
, Target.[Discount_Rate] = Source.[Discount_Rate]
, Target.[PS_Id] = Source.[PS_Id]
, Target.[PS_Goods_Id] = Source.[PS_Goods_Id]
, Target.[C_Shop_Group] = Source.[C_Shop_Group]
, Target.[C_Status] = Source.[C_Status]
, Target.[Stock_Status] = Source.[Stock_Status]
WHEN NOT MATCHED BY TARGET THEN
    INSERT (
 AutoId , Order_Id , Goods_Id , CusGoods_Id , Goods_Name , Goods_Color , Goods_Spec , Qty , Unit , Price , Amount , Maker , MakeDate , Remark , Base_Price , Item_Mark , Weight , Pic , Discount_Rate , PS_Id , PS_Goods_Id , C_Shop_Group , C_Status , Stock_Status     )VALUES (
 Source.AutoId , Source.Order_Id , Source.Goods_Id , Source.CusGoods_Id , Source.Goods_Name , Source.Goods_Color , Source.Goods_Spec , Source.Qty , Source.Unit , Source.Price , Source.Amount , Source.Maker , Source.MakeDate , Source.Remark , Source.Base_Price , Source.Item_Mark , Source.Weight , Source.Pic , Source.Discount_Rate , Source.PS_Id , Source.PS_Goods_Id , Source.C_Shop_Group , Source.C_Status , Source.Stock_Status     );
 SET IDENTITY_INSERT m2c_final.dbo.m2c_SOM_Order_Items OFF;

原创粉丝点击