Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Detecte trailing record

Author  Topic 

CanadaDBA

583 Posts

Posted - 2004-12-02 : 12:38:31
My text file has a trailing record like: TRAILER RECORD0000000851

This will cause problem for my import DTS. How can I get ride of the trailing record?

Thanks,


Canada DBA

X002548
Not Just a Number

15586 Posts

Posted - 2004-12-02 : 12:44:29
Don't you want to audit the file?

What's the table DDL look like

What's the file look like(Delimited, fixed width?)



Brett

8-)
Go to Top of Page

CanadaDBA

583 Posts

Posted - 2004-12-02 : 13:18:27
The file is being generated everyday by mainframe and I don't want to mannually change it.

I couldn't get this: What's the table DDL look like

It is fixed width. Like:
00000000210000000029001593400023630000000000000002SYLVI HAYAN

quote:
Originally posted by X002548

Don't you want to audit the file?

What's the table DDL look like

What's the file look like(Delimited, fixed width?)



Brett

8-)



Canada DBA
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-02 : 13:55:38
Take a look at these:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41614
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=42436

That's probably the easiest way to do it.
Go to Top of Page

CanadaDBA

583 Posts

Posted - 2004-12-03 : 10:20:17
Thanks robvolk. I could remove the trailing row from the text file and create a new text file.

FindSTR /V "TRAILER" Insurance.txt > InsuNew.txt

Since I am going to use an SP and DTS, I have to run this command from within the SP and then call the DTS, right? Do you have better suggestion?
quote:
Originally posted by robvolk

Take a look at these:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41614
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=42436

That's probably the easiest way to do it.



Canada DBA
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-03 : 10:46:00
You can add an Execute process task to your DTS package to run findstr before it executes the rest of the steps.

As an alternative, you could use bcp with a format file to import the new text file (you need a format file to import fixed-width data) Doing this will let you avoid DTS entirely. Both findstr and bcp can be put into a batch file that is called from a job, or as individual job steps. You can then call the job using the sp_start_job procedure, or schedule it to run whenever you wish.

There's nothing wrong with using DTS for this but it's not really necessary or beneficial either, the process is pretty simple.
Go to Top of Page

CanadaDBA

583 Posts

Posted - 2004-12-03 : 11:59:52
Both findstr and bcp can be put into a batch file
Then I have to have the batch file somewhere in my server. I have to avoid having external files but I can put both lines in a SP and execute them from within that SP.

I need to put each data in its own field. Does bcp do it? I am going to BOL to study the bcp.

Canada DBA
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-03 : 12:09:52
Doing it as a regular job lets you avoid a batch file. You *can* use a stored procedure but I don't see any benefit to it.

bcp and BULK INSERT can't parse out fixed-length data without a format file. If you absolutely can't have external files, you can import the entire line into a varchar(8000) staging table and parse it from there.
Go to Top of Page

CanadaDBA

583 Posts

Posted - 2004-12-03 : 14:04:30
Yes, you are right. I totally forgot about format file. I am studing bcp.

I couldn't get this:Doing it as a regular job lets you avoid a batch file.what do you mean?

Canada DBA
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-03 : 14:09:22
Instead of putting both findstr and bcp into a batch file and running it, you can create a job and add two CmdExec steps. The first step runs findstr, the 2nd runs bcp. When the job runs both steps will be executed.
Go to Top of Page
   

- Advertisement -