Solved

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

Posted on 2010-11-16
2
606 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now