sql - How to know that MERGE operation was INSERT or UPDATE? -
let have,
merge share_ad_group using ( select share_ad_group_id, share_id, ad_group, share_permissions share_ad_group share_id = @shareid , ad_group = @ownerid ) b on (a.share_ad_group_id = b.share_ad_group_id) when matched update set a.share_permissions = b.share_permissions when not matched insert (share_permissions) values(@sharepermissions); -- in here how know insert or update
how know merge operation insert or update after insert or update?
please refer here
declare @summaryofchanges table(change varchar(20)); merge tbltarget target using (select col1,col2 tblsource) source on (target.col1 = source.col1) when matched update set target.col2 = source.col2 -- need affected rows here when not matched target insert (col1,col2) values (col1,col2); -- need affected rows here output $action @summaryofchanges; select change, count(*) countperchange @summaryofchanges group change;
Comments
Post a Comment