I have a small problem with inserting information from one table to other.
For example: from table A (can contain ~10 kk entries) to table B, tables are identical except table A has DateTimeStamp which is used to take certain data (boundaries).
So I need to move data from A to B (without DateTimeStamp) and remove duplicates from B.
Example:
Table A
DateTimeStamp | Key | value
2012-02-03 | 2 | 123
2012-02-03 | 3 | 985
2012-02-03 | 5 | 1584
Table B
Key | value
8 | 45
3 | 785
9 | 7457
So I need to delete row with Key = 3 from Table B and insert everything else from Table A.
Results would be:
Key | value
8 | 45
3 | 985
9 | 7457
2 | 123
5 | 1584
Is there elegant way to do this ? Triggers are too slow, and I am looking for solution that wouldn’t require temporary table.
SQL Server or SSIS solutions\suggestions are welcome
If you’re using SQL Server 2008 or newer, you could do this very easily with a single
MERGEstatement – something like this: