﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Discuss content posted by Theo Ekelmans / Article Discussions by Author  / Compare 2 datasets and output delta in one TSQL statement / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 04:11:08 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Compare 2 datasets and output delta in one TSQL statement</title><link>http://www.sqlservercentral.com/Forums/Topic1200330-596-1.aspx</link><description>[code="sql"]--Compareandinsertdeltaintotable,inonesqlstatementInsert into #cmpAB([EmpNr_a],[EmpNr_b],[Name_a],[Name_b],[HireDT_a],[HireDT_b],[FireDT_a],[FireDT_b])SELECT a.[EmpNr],b.[EmpNr],a.[Name] ,  b.[Name],a.[HireDT] , b.[HireDT] , a.[FireDT] , b.[FireDT]FROM #tblA a  INNER JOIN #tblB bON a.[EmpNr] = b.[EmpNr]WHERE( a.[Name] &amp;lt;&amp;gt;  b.[Name] OR a.[HireDT] &amp;lt;&amp;gt; b.[HireDT] OR a.[FireDT] &amp;lt;&amp;gt; b.[FireDT])UNION SELECT a.[EmpNr],b.[EmpNr],a.[Name] ,  b.[Name],a.[HireDT] , b.[HireDT] , a.[FireDT] , b.[FireDT]FROM #tblA a  FULL OUTER JOIN #tblB bON a.[EmpNr] = b.[EmpNr]where (a.[EmpNr] IS NULL OR b.[EmpNr] IS NULL)--Thanks Mitesh Oswal [/code]</description><pubDate>Sun, 27 Nov 2011 21:34:28 GMT</pubDate><dc:creator>Mitesh Oswal</dc:creator></item><item><title>RE: Compare 2 datasets and output delta in one TSQL statement</title><link>http://www.sqlservercentral.com/Forums/Topic1200330-596-1.aspx</link><description>Hi,As with any unbalanced compare, the performance varies.Just compare this method with use your favorite compare and look closely at the execution planIn my query close to 50% of the time is spent reading the 2 source tables using a clustered index scan, which is the most efficient way to read the ENTIRE table content. The Merge join that does the actual compare work is only 19 % of the timeThe rest: 33%, is spent storing the result.If you find a more efficient way, i'd be happy to review your code!Theo :)</description><pubDate>Sun, 06 Nov 2011 08:52:50 GMT</pubDate><dc:creator>Theo Ekelmans</dc:creator></item><item><title>RE: Compare 2 datasets and output delta in one TSQL statement</title><link>http://www.sqlservercentral.com/Forums/Topic1200330-596-1.aspx</link><description>OK, now the code is showing. Thanks.</description><pubDate>Fri, 04 Nov 2011 05:51:06 GMT</pubDate><dc:creator>macrocharlie</dc:creator></item><item><title>RE: Compare 2 datasets and output delta in one TSQL statement</title><link>http://www.sqlservercentral.com/Forums/Topic1200330-596-1.aspx</link><description>Any idea on how well this scales, or its performance versus using a full join between the two tables with a WHERE clause where either side is NULL?</description><pubDate>Fri, 04 Nov 2011 05:36:15 GMT</pubDate><dc:creator>tsceurman</dc:creator></item><item><title>RE: Compare 2 datasets and output delta in one TSQL statement</title><link>http://www.sqlservercentral.com/Forums/Topic1200330-596-1.aspx</link><description>Where's the code?</description><pubDate>Fri, 04 Nov 2011 05:12:55 GMT</pubDate><dc:creator>macrocharlie</dc:creator></item><item><title>Compare 2 datasets and output delta in one TSQL statement</title><link>http://www.sqlservercentral.com/Forums/Topic1200330-596-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/T-SQL/76689/"&gt;Compare 2 datasets and output delta in one TSQL statement&lt;/A&gt;[/B]</description><pubDate>Thu, 03 Nov 2011 21:02:45 GMT</pubDate><dc:creator>Theo Ekelmans</dc:creator></item></channel></rss>