Solved

Update a Table from a text file by running a store procedure......

Posted on 2010-11-16
2
608 Views
Last Modified: 2013-11-30
I have a table: TableTest in Mircosoft SQL Server that I would like to get updated on a regular basis when the Update.txt file get updated. The txt file reside on the SQL server

All the content of the txt file need to replace the content of the table once the text file get updated.

Should I write a store procedure for this and if so? How do I do this?
Text File: Update.Txt

V04510;5/28/2009;00729783;Q10070849I;9/29-30/07 RMB INV#22738;156;SHORT, JUDY

Table TableTest

SELECT TOP 1000 [Vendor Number]
      ,[Date]
      ,[Check Number]
      ,[Reference Number]
      ,[Description]
      ,[Payment Amount]
      ,[payee]
  FROM [AdvancePayroll].[dbo].[TableTest]
0
Comment
Question by:yguyon28
2 Comments
 
LVL 10

Accepted Solution

by:
wls3 earned 166 total points
ID: 34146912
I tend to try and do this in two steps:

1) run a batch file as a scheduled task on whatever interval you need.  The body works well like this (assuming sqlcmd):

sqlcmd -S Yourserver\instancename -U username -P password -i "C:\script.sql"

alternately, you can use a trusted connection

sqlcmd -S yourserver\instancename -E -i "C:\script.sql"

If you do not specify the instance name, you may run into what appear to be funky connectivity errors.

2) store the body of the script in a file with a .sql extension (referenced above as C:\script.sql).  This would contain something to the effect of:

BULK INSERT [AdvancePayroll].[dbo].[TableTest]
    FROM 'c:\update.txt'
    WITH
    (
        FIELDTERMINATOR = ';',
        ROWTERMINATOR = '\n'
    )

Refer to this article for BCP examples:

http://sqlserver2000.databases.aspfaq.com/how-do-i-load-text-or-csv-file-data-into-sql-server.html
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server Generate Scripts Fails 5 36
create an aggregate function 9 34
Inserting oldest record into new table. 5 24
Sql server, import complete table, using vb.net 9 35
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question