Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Dynamic SQL Merge Expand / Collapse
Author
Message
Posted Tuesday, April 7, 2009 12:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 7:59 AM
Points: 22, Visits: 258
Comments posted to this topic are about the item Dynamic SQL Merge
Post #691709
Posted Tuesday, April 7, 2009 5:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 18, 2014 12:44 PM
Points: 1, Visits: 22
What about using of tablediff utility?
Post #691870
Posted Tuesday, April 7, 2009 9:34 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Friday, April 4, 2014 4:40 PM
Points: 751, Visits: 917
I think this procedure is impressively well done.

With that said, It does seem to be a bit of a solution looking for a problem. Writing the merge statement directly is not at all challenging and it seems easier to simply do that then learn the nuances of this procedure, especially since writing it directly permits it to be made more nuanced if so desired.


---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Post #692189
Posted Tuesday, April 7, 2009 9:39 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, July 21, 2014 12:34 PM
Points: 1,157, Visits: 3,255
Nice Glen :)

I just posted a similar SP - just went about a little different.....

http://www.sqlservercentral.com/scripts/SQL+2008/66507/


Tommy

Post #692199
Posted Wednesday, April 8, 2009 12:56 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, May 10, 2009 9:29 PM
Points: 29, Visits: 6
Thank you so much for posting this!

Post #692791
Posted Friday, March 15, 2013 7:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, February 12, 2014 11:43 AM
Points: 1, Visits: 3
Excellent work. Never mind the comment about this being a solution looking for a problem, this proc was exactly what I needed. We have lots of different reference data tables what I want to keep "relatively" in sync and this gives me 99% of what I need. The other 1% I can tweak the proc to make happen.

One thing, in your example 2, merging from a linked server, I believe you need to change the @srcType value sent in to 'LINK' from 'SQL'. That's what I needed to do in order to pull from the linked server. It wouldn't work otherwise.

Post #1431536
Posted Friday, March 15, 2013 8:15 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 7:59 AM
Points: 22, Visits: 258
Thank you very much for your kind feedback. Your comments are correct regarding the "link". The actual usage for this was originally to an AS400 linked server.

As so often happens when you provide a tool which makes coding easier, I've now had to re-train folks so that they don't over-use the MERGE statement:)
Post #1431559
Posted Monday, December 2, 2013 12:37 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 11:03 AM
Points: 34, Visits: 254
This is a great piece of code. One change I would recommend is in step 4 using NULLIF so if the source or destination contains a null it is caught.

Something like this:

SELECT @TempSQL = @TempSQL + 'NULLIF(S.'+cols.SrcColumn+', T.'+cols.SrcColumn+') IS NOT NULL or '


Thanks!
Post #1518999
Posted Tuesday, December 3, 2013 5:57 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 7:59 AM
Points: 22, Visits: 258
Good thought there. I appreciate your comments.
Post #1519451
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse