Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Need help to read text file Expand / Collapse
Author
Message
Posted Tuesday, March 19, 2013 6:49 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 23, 2014 9:39 PM
Points: 44, Visits: 505
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


  Post Attachments 
AG-Persekutuan-Bln-09-2012.txt (7 views, 730 bytes)
Post #1432613
Posted Tuesday, March 19, 2013 7:39 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:49 PM
Points: 13,069, Visits: 11,908
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/

_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1432645
Posted Tuesday, March 19, 2013 6:11 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 23, 2014 9:39 PM
Points: 44, Visits: 505
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/


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?
Post #1432955
Posted Tuesday, March 19, 2013 6:27 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 2:28 PM
Points: 33,062, Visits: 15,174
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







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1432957
Posted Tuesday, March 19, 2013 7:07 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 23, 2014 9:39 PM
Points: 44, Visits: 505
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.
Post #1432969
Posted Tuesday, March 19, 2013 8:54 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 2:28 PM
Points: 33,062, Visits: 15,174
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.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1432978
Posted Wednesday, March 20, 2013 12:11 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 11:31 AM
Points: 36,728, Visits: 31,180
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1433009
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse