Brandie Tarvin (7/17/2013)
Not only did I just teach myself how to use MERGE (never had time or reason), but I managed to use it correctly with a Cross Applied Tally table and an INNER JOIN inside the USING clause.
And it only took me 30 minutes to figure it all out.
One thing to take care with when using MERGE though: A Hazard of Using the SQL Merge Statement[/url]
It's not a bug it's a feature, but does have the potential to cause you grief if you don't know about it.
That reference is one of the most stupid pieces of nonsense I've ever seen. First the guy says he wants to merge his source into his target. Then he produces a chunk of code which does something like that. But the result of that is not what was required, because it's failed to delete a row that was in the target but not matched in the source - in other words, because it failed to violate his stated requirement in a particular way in which he wants his stated requirement violated. He then produces a piece of utterly silly code which just destroys his target and substitutes the source - and we are supposed to be surprised that that doesn't work. Then he produces, finally, his code which is the answer to the problem - but it doesn't meet his stated requirement, because it does indeed achieve the violation of that requirement that he introduced earlier to do job which he apparently wants, instead of the requirement that was actually fulfilled by the first piece of code he rejected. I just hope that I never have to deal with a developer or a DBA who leant from that guy!