导入数据时, 存在的更新, 不存在的插入

WBOY
发布: 2016-06-07 14:56:39
原创
1372 人浏览过

导入数据时, 存在的更新, 不存在的插入 无 CREATE?trigger?tr_bank3?ON?bank3AFTER?INSERTAS??????Update?bank1?set?bank1.fmoney=bank1.fmoney+c.a???????From?????????(select?fid,sum(case?when?TYPE=0?then?fmoney?when?type=1?then?-fmoney?end)?as?a?Fr

导入数据时, 存在的更新, 不存在的插入
CREATE?trigger?tr_bank3?ON?bank3
AFTER?INSERT
AS
?
?
????Update?bank1?set?bank1.fmoney=bank1.fmoney+c.a?
??????From?
????????(select?fid,sum(case?when?TYPE=0?then?fmoney?when?type=1?then?-fmoney?end)?as?a?From?bank3?group?by?Fid)?C?
????where?
????????C.FID=bank1.FID?
????????AND?EXISTS(SELECT?1?FROM?INSERTED?WHERE?Fid=bank3.Fid))
?
????insert?into?bank1?
????select?
????????fid,
????????sum(case?when?TYPE=0?then?fmoney???when?type=1?then?-fmoney?end)?as?a?
????from?
????????bank3?AS?a
????WHERE?
????????EXISTS(SELECT?1?FROM?INSERTED?WHERE?Fid=a.Fid)
????AND?
????????NOT?EXISTS(SELECT?1?FROM?bank1?WHERE?Fid=a.Fid)
????group?by?Fid
登录后复制
MERGE [target] t
using [source] s on t.id = s.id
when matched then update t.name = s.name, t.age = s.age -- use "rowset1"
when not matched then insert values(id,name,age) -- use "rowset2"
when source not matched then delete; -- use "rowset3"
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板