on 2021 Nov 22 10:08 AM
I have table LOCNAG_ENT and jsut for test i cloned this table and changed some ENTERPRISE_ID for exact LOCACCESSGRP_ID and trying to merge.
But when it goes to DELETE i have "syntax error near 'DELETE' on line 5'
And i can't catch why?
And also do we have some similar behaviour like in SLQ Server?
For "WHEN MATCH BY SOURCE"
MERGE INTO LOCNAG_ENT as tgt
USING LOCNAG_ENT_CLONE src
on src.LOCACCESSGRP_ID=tgt.LOCACCESSGRP_ID and src.ENTERPRISE_ID=tgt.ENTERPRISE_ID
when matched then skip
WHEN NOT MATCHED and src.ENTERPRISE_ID <> tgt.ENTERPRISE_ID and src.LOCACCESSGRP_ID <> tgt.LOCACCESSGRP_ID THEN DELETE
WHEN NOT MATCHED and tgt.LOCACCESSGRP_ID <> src.LOCACCESSGRP_ID and tgt.ENTERPRISE_ID <> src.ENTERPRISE_ID THEN INSERT (LOCACCESSGRP_ID, ENTERPRISE_ID)
values(src.LOCACCESSGRP_ID, src.ENTERPRISE_ID)
How can i procceed with logic if i have same values from both tables (agrp_id, enterpsie_id) then just skip, if i have new values in source table but doesn't have in target, then insert, if i doesn't have values in source table which have target table, then delete them?
DELETE is not permitted in a NOT MATCH.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A second MERGE that deals with the DELETE but formed as a WHEN MATCHED would be an option.
User | Count |
---|---|
71 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.