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

WBOY
發布: 2016-06-07 14:56:39
原創
1371 人瀏覽過

导入数据时, 存在的更新, 不存在的插入 无 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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板