Solved

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

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

733 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