April 7, 2009 at 10:45 am
Comments posted to this topic are about the item SQL 2008 MERGE using Dynamic SQL over a Linked Server
Tommy
Follow @sqlscribeMarch 16, 2011 at 9:30 am
Thanks Tommy for this great procedure.
But there's a problem if you want to merge a table with more than 2 columns in the PK.
If you change
SELECT @pk_2 = 'AND ' + @local_schema_name + '_TARGET.' + column_name + ' = ' + @local_schema_name + '_SOURCE.' + column_name
FROM @pk_table WHERE key_seq = 2
into
SET @pk_2 = '';
SELECT @pk_2 = @pk_2 + ' AND ' + @local_schema_name + '_TARGET.' + column_name + ' = ' + @local_schema_name + '_SOURCE.' + column_name
FROM @pk_table WHERE key_seq > 1;
you can also handle tables with more than 2 columns as a PK.
Best regards
Helmut
March 16, 2011 at 10:37 am
Very good point Helmut, thank you!
Tommy
Follow @sqlscribeMay 19, 2016 at 7:04 am
Thanks for the script.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy