Solved

SQL Server Schedule job to dump txt data into a table

Posted on 2002-04-18
4
265 Views
Last Modified: 2012-06-27
Hi

It would great if someone could help me out as to how to load a text file with comma delimeted into a table on  SQL Server  and to run a scheduler to do this job every day

Thanks
0
Comment
Question by:Richards
  • 2
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
First, how can data be loaded:
* BCP (a command line tool, see books online how this works)
* BULK INSERT (a TSQL command, same as BCP)
* DTS (a feature in SQL Server to load data using ODBC driver/OLEDB interface)

When you have choosen/tested those functions, you can then automate this process:
* BCP: create a job, with one step. The step can be of type Command, and you only type in the command to run BCP with all the options.
* BULK INSERT: same as BCP, only that you have a step of type TSQL, and give the TSQL line needed
* DTS: once you have your DTS package ready, just right-click it and choose schedule. See in the job list a new job that you might customize regarding the schedule.

Tip:
load the data always to a staging table, which doesn't check for data consistency and data types immediately. Do these kind of checks after loading, and then copy/move the records to the final table.

CHeers
0
 

Author Comment

by:Richards
Comment Utility
Thanks ! Can I have an example of any of them say I have in a text file text.txt in C:\

record 1 , RollNo , Name , age
record 1 , RollNo , Name , age

and a table name test which have the four fields

How can I use the DTS to do it . Is there any documentation for it ?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
For SQL DTS docu on the web:
http://www.sqldts.com/

A simple example of BULK INSERT:
BULK INSERT test from 'c:\test.txt'
WITH FIELDTERMINATOR = ',' , FIRSTROW = 1

With BCP:
BCP yourdb..test IN "c:\test.txt" -F 1 -t "," -S server_name-U login_id -P password -

CHeers
0
 

Author Comment

by:Richards
Comment Utility
Thanks ! Can you let me know where will i insert the sql and how to run the Scheduler?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

9 Experts available now in Live!

Get 1:1 Help Now