码迷,mamicode.com
首页 > 其他好文 > 详细

使用 changes——Merge

时间:2015-05-09 13:18:56      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

insert into Book ( ISBN , Price , Shelf , archivedAt )
select ISBN , Price , Shelf , getdate() from
( merge book as b
    using WeeklyChange as wc
      on b.ISBN=wc.ISBN and b.archivedAt is null
  when matched and ( b.price<>wc.price or b.shelf<>wc.shelf ) then
     update set b.price=wc.price , b.shelf=wc.shelf
  when not matched then
     insert values(wc.ISBN , wc.price , wc.shelf)
  output $action , wc.ISBN , Deleted.Price , Deleted.Shelf
)  changes( action , ISBN , Price , Shelf)
   where action=‘update‘ ;

使用 changes——Merge

标签:

原文地址:http://www.cnblogs.com/LvanHades/p/4489671.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!