Link to home
Create AccountLog in
Avatar of gaz1000
gaz1000

asked on

create procedure to insert/update a table every night

Hi,

I'm fairly new to using SQL server but I'm looking to insert new records into a table every night  or else update to current records.

As an example I've created a table with the following fields: id,FirstName,Age and City.

I've created a text file with the following:

      123a      Garry      30      Leeds
      23fr      Mike      33      London
      a29k      Tony      32      New York
      a34f      John      27      Manchester
      asdr      Claire      18      Liverpoool
      f56g      James      14      Dublin

and updated my table using the following SQL:

BULK insert customer
        FROM 'c:\cust.dat'
            WITH
          (
                FIELDTERMINATOR = '|',
                ROWTERMINATOR = '\n'
              )
GO

SELECT * FROM customer

GO

Every night a text file will be created with records as shown above, and I want to insert new records or update existing records.

How do I create an SQL proc(I assume) to do this?

I would prefer if you could give me the actual SQL which I can test rather than links to other tutorial sites.

Thanks,

ASKER CERTIFIED SOLUTION
Avatar of frankytee
frankytee
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer