Auto-generate MERGE comparison clauses
One of the most tedious elements of writing T-SQL is handling of proper comparisons in the WHEN MATCHED AND ... THEN UPDATE clause of a MERGE statement.
For example, to compare a single nullable target and destination column you should compare:
SRC.column <> TGT.column
OR (SRC.column IS NULL AND TGT.column IS NOT NULL)
OR (SRC.column IS NOT NULL AND TGT.column IS NULL)
I'm not sure on exactly how would be best to handle this but it would be great if SQL Prompt could somehow auto-populate these clauses. Or even better would be some way to generate an entire merge statement for two similar tables. When merging tables with many columns, this would be a huge time-saver. Additionally, these comparisons are highly susceptible to user-error do to the repetitive nature of the task.
-
Anonymous commented
Can I upvote this like 10 times? My merge has 30 columns in it. What a PITA!