Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-11-16
2
Medium Priority
?
624 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
wls3 earned 664 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

604 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