Need help to read text file

  • Hi,

    My text file as attachment ~ AG-Persekutuan-Bln-09-2012.txt

    How to read this file as follows,

    1. Taxpayer data starting in the second row

    2. The 1st TaxPayer read as follows,

    SUBSTRING('02029105500000326272560816105987 Samat Bin Sani 0000015004363 ',21,6) +

    '-' +

    SUBSTRING('02029105500000326272560816105987 Samat Bin Sani 0000015004363 ',27,2) +

    '-' +

    SUBSTRING('02029105500000326272560816105987 Samat Bin Sani 0000015004363 ',29,4) as newIdx,

    SUBSTRING('02029105500000326272560816105987 Samat Bin Sani 0000015004363 ',52,40) as myName

    3. The 2nd TaxPayer read as follows,

    SUBSTRING('02011105700000488437551130055335 Jalaludin Bin Jalil 0000025004363 ',21,6) +

    '-' +

    SUBSTRING('02011105700000488437551130055335 Jalaludin Bin Jalil 0000025004363 ',27,2) +

    '-' +

    SUBSTRING('02011105700000488437551130055335 Jalaludin Bin Jalil 0000025004363 ',29,4) as newIdx,

    SUBSTRING('02011105700000488437551130055335 Jalaludin Bin Jalil 0000025004363 ',52,40) as myName

    4. And the next reading as like above

    5. After all the content is read, the result as follow

    560816-10-5987 SAMAT BIN SANI

    551130-05-5335 JALALUDIN BIN JALIL

    590826-05-5028 MUKARRAMAH BT IBRAHIM

    550317-05-5242 FATIMAH BT ISMAIL

    540301-04-5163 ABU MANSOR BIN HJ MOHD NOR

    It's possible SQL Server 2008 R2 read text file? If yes, I really need help. Please help me. I'm stuck

  • Probably the easiest way to import this type of thing is with SSIS. Check out the stairways series here. http://www.sqlservercentral.com/stairway/72494/[/url]

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (3/19/2013)


    Probably the easiest way to import this type of thing is with SSIS. Check out the stairways series here. http://www.sqlservercentral.com/stairway/72494/[/url]

    tq sir.

    Just have a look the SSIS. My question is, how SSIS import text file, and extract the record based on substring as above?

  • Did you look at the link?

    The second article talks about imports: http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/72493/

    When you do the import, you'll need to then separate out the various parts of the data. This isn't a simple quick thing to answer. What is probably easiest for you is to use the Import Wizard and import to a staging table. Then use T-SQL to separate out the rows.

    http://msdn.microsoft.com/en-us/library/ms140052.aspx

  • Steve Jones - SSC Editor (3/19/2013)


    Did you look at the link?

    The second article talks about imports: http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/72493/

    When you do the import, you'll need to then separate out the various parts of the data. This isn't a simple quick thing to answer. What is probably easiest for you is to use the Import Wizard and import to a staging table. Then use T-SQL to separate out the rows.

    http://msdn.microsoft.com/en-us/library/ms140052.aspx

    Tq sir. Dont angry with me sir. 😛

  • Not angry, just asking. From your next question, it didn't appear you had actually looked at SSIS.

    We are happy to help, and point you in the right direction, but we're not here to do your work or explain everything in great detail. We expect you to take our advice and information, do some research and testing on your own.

  • idyana (3/19/2013)


    Hi,

    My text file as attachment ~ AG-Persekutuan-Bln-09-2012.txt

    How to read this file as follows,

    1. Taxpayer data starting in the second row

    2. The 1st TaxPayer read as follows,

    WHOA! Hold the phone and back the privacy truck up! Are these REAL taxpayer numbers? If so, please go back and drop the text file attachment and delete the entries from your post!

    Then find the person that's setting up these files with the information in clear-text and report them! This is SO wrong if these are real.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply