Importing a fixed-width text file

Posted on 2004-12-01
Last Modified: 2008-02-01
I have a variable length fixed-width text file.  I am transferring this file from a mainframe via ftp using sdi32 within a DTS package.

The file has as it's last field a 1 char indicator.  If this indicator is blank the file contains the crlf in the position of the last field instead of after the position of the last field.  If this short record is the first record in the file then sql incorrectly determines this to be the end of the record position for all the records.  


190002669565199706149910    C00000000000000000000000000000PPH                        9920      TEMPORARY EMPLOYEES 01NT04200000950000000 Y00000000000VT19970815        NNNSO00000NRCY00100--End of record 1

190002669565199612279910    C00000000000000000000000000000PPH                        9920      TEMPORARY EMPLOYEES 01NC04200000950000000 Y00000000000VT19970110        NNNAC00000NRCY00100N--End of record 2

As a work-around I use Access as a middleware translator because Access correctly determines the length of the record.  I would like to get away from using Access as a translator.  

I researched awhile ago and this was a documented problem from Microsoft.  

My question is:  Is there a fix for this or some other cleaner way to import this file?


Question by:RacinRan
    LVL 1

    Accepted Solution

    DTS also allows to write code (VBScript) to process records one by one. That way you will be able to write conditions, check end of file/line characters and process each row accordingly.

    LVL 3

    Expert Comment

    What a %#@^! that is! You could always create a DTS job as normal, but instead of running it, save it as a Visual Basic File. You can then open the file and edit the column length for the last column to be one more than length that the DTS job create. Then you just run the DTS VB file as per usual.
    LVL 14

    Expert Comment

    just simple!!

    Downloads the utility DB Tools and impot this all.

    LVL 3

    Author Comment


    I was hoping not to have to do that.


    No kidding.  :)   I tried your suggestion ... but it still throws the subsequent records because it then interprets the crlf that is positioned incorrectly.


    Could you post a link?


    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    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…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    732 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

    18 Experts available now in Live!

    Get 1:1 Help Now