Forum Discussion
pmscorca
1 year agoKudo Kingpin
Support for MERGE statement
Hi, reading the documentation I've noticed the absence of the MERGE statement. Does Fabric support this more important statement? Why not? A such statement is very very important to work with a da...
- 1 year ago
pmscorca ,
I agree, it is a handy syntax.
It seems, MS is already working on it though 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
tackytechtom
1 year agoMost Valuable Professional
Hi pmscorca ,
You are right, it seems ot be a current limitation:
T-SQL surface area - Microsoft Fabric | Microsoft Learn
However, you might be able to use another syntax than the merge statement, e.g. the code below:
MERGE INTO target_table AS target
USING source_table AS source
ON target.id = source.id
WHEN MATCHED THEN
UPDATE SET
target.col1 = source.col1,
target.col2 = source.col2
WHEN NOT MATCHED THEN
INSERT (id, col1, col2)
VALUES (source.id, source.col1, source.col2);
translates to:
UPDATE target_table
SET
target_table.col1 = source_table.col1,
target_table.col2 = source_table.col2
FROM source_table
WHERE target_table.id = source_table.id;
INSERT INTO target_table (id, col1, col2)
SELECT source_table.id, source_table.col1, source_table.col2
FROM source_table
LEFT JOIN target_table
ON source_table.id = target_table.id
WHERE target_table.id IS NULL;
Let me know, if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
- pmscorca1 year agoKudo Kingpin
Hi, thanks for your reply, but I know that it occurs to use an update and an insert statements when merge statement isn't available.
The focus of the post is about the merge statement ... having a such feature is very very important.
Thanks