Here is a situation that I am trying to resolve. I have a table that is loaded with duplicates. It happened because similar rows were loaded from two different sources. That is
Maybe it will help you
;WITH cte AS
(
SELECT ROW_NUMBER() OVER (PARTITION BY UID, ADDRESS, City, State, Zip, DataSource ORDER BY UID) AS Dup
FROM dbo.F_staRes
)
DELETE cte
WHERE Dup > 1
EXCEPT returns any distinct values from the left query that are not also found on the right query. INTERSECT returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand
http://msdn.microsoft.com/zh-cn/library/ms188055.aspx
To achieve your perpose, you could try the command merge.
;
merge into #Clevland as target
using #Ohio as source
on (target.UID = source.UID) -- you could add ADDRESS,City,State,Zip
when not matched
insert into target (UID) values (source.UID)
;
Wish this will help.