Data Load Based on Rank

Last Post 10 Aug 2007 10:38 PM by SQLUSA. 1 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
johowar1
New Member
New Member

--
09 Aug 2007 09:07 AM
I'm fairly new to SQL and I have been asked to load multiple tables with duplicate and inconsistent data into a single table. Each source (table) has been assigned a rank in terms of the quality and reliability. After some thought, I have come up with this solution to get all of the data loaded based on rank.

Does anyone know of a better way to do this?

Value is a unique key.

SELECT *
FROM table_1

union

SELECT *
FROM table_2
where (value + '_' + yr) in
( select value + '_' + yr
from table_2
except
select value + '_' + yr
from table_1)

union

SELECT *
FROM table_3
where (value + '_' + yr) in
( select value + '_' + yr
from table_3
except
select value + '_' + yr
from table_2
except
select value + '_' + yr
from table_1)
SQLUSA
New Member
New Member

--
10 Aug 2007 10:38 PM
Yes. It is a neat solution.

Kalman Toth - Database, Data Warehouse & Business Intelligence Architect
SQLUSA: http://www.sqlusa.com/order2005grandslam/ - The Best SQL Server 2005 Training


Acceptable Use Policy
---