Unix Technical Forum

How to insert new rows to master table

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 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:27 AM
keys4worship
 
Posts: n/a
Default How to insert new rows to master table

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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:27 AM
David Portas
 
Posts: n/a
Default Re: How to insert new rows to master table

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
--


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:27 AM
keys4worship
 
Posts: n/a
Default Re: How to insert new rows to master table

Thanks

I will try this at work in the morning.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:58 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com