• Grey Twitter Icon
  • Grey Facebook Icon
  • Grey LinkedIn Icon
  • Grey Google+ Icon

© 2016 - 2019 All rights reserved. PigeonSQL.com | Filip Holub

Dynamic SQL Merge Script for Generate Merge statement

April 4, 2018

One day I needed to compare the tables where the source tables were production database and the target tables were for reporting database.

Therefore I built dynamic script via T-SQL that generate MERGE statement.

If in reporting table missed any data this MERGE statement inserted them from production table.

 

The biggest problem is in use MERGE, you can have problem if on the table is not the identity column, REFERENCE constraint, etc... So, It's very limited, but sometimes can be useful.

 

HERE is my Dynamic SQL Merge Script:

 

 

As you can see, you have to write your table name with schema and database name in @dst and @src varibles.

 

See you next time guys!

 

 

 

 

Please reload

RECENT POST
Please reload

  • Facebook Social Icon
  • Google+ Social Icon
  • LinkedIn Social Icon
  • Twitter Social Icon