Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help to read text file


Need help to read text file

Author
Message
Qira
Qira
SSC-Enthusiastic
SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)

Group: General Forum Members
Points: 106 Visits: 734
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
Attachments
AG-Persekutuan-Bln-09-2012.txt (7 views, 730 bytes)
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16616 Visits: 17024
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)
Qira
Qira
SSC-Enthusiastic
SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)

Group: General Forum Members
Points: 106 Visits: 734
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?
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36162 Visits: 18751
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
My Blog: www.voiceofthedba.com
Qira
Qira
SSC-Enthusiastic
SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)SSC-Enthusiastic (106 reputation)

Group: General Forum Members
Points: 106 Visits: 734
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. :-P
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36162 Visits: 18751
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
My Blog: www.voiceofthedba.com
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45147 Visits: 39923
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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search