This is a discussion on How to insert new rows to master table within the SQL Server forums, part of the Microsoft SQL Server category; --> I use Ftp to import a comma delim file. Problem: Day 1 file has 5 records. During the course ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I use Ftp to import a comma delim file. Problem: Day 1 file has 5 records. During the course of Day 1 ,users make changes to a field in the five records. Day 2 has same 5 records as they were at the beginning of Day 1(without changes made during Day 1) plus 1 new record. I need a statement that will only add the 1 new record to the master table and leave the other 5 fields alone. I have a composite key that prevents duplicate addition. My original idea was to have a master table(Day 1) and a daily table(Day 2) and do some kind of join that would give we only the records in Day 2 that do not appear in Day 1 using the Composite key. This has not worked. Any ideas? |
| |||
| INSERT INTO MasterTable (key_col, col1, col2, ...) SELECT D.key_col, D.col1, D.col2, ... FROM DailyTable AS D LEFT JOIN MasterTable AS M ON D.key_col = M.key_col WHERE M.key_col IS NULL -- David Portas SQL Server MVP -- |