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 2005 Forums
 Transact-SQL (2005)
 How to read TXT file

Author  Topic 

Zoran035
Starting Member

5 Posts

Posted - 2010-07-27 : 04:49:28
I have source file A.TXT
----------------------------------------------------
100140720102223470000103
200XXXX 000015000000010007000
200YY 000019000000010001600
200Z 000007000000010011200
3000000004100000

when do T-SQL
-- Create a table to hold the data
CREATE TABLE #textfile (line varchar(8000))
-- Read the text file into the temp table
BULK INSERT #textfile FROM 'c:\A.TXT'
GO
-- Now read it
SELECT * FROM #textfile
-- And then clean up
DROP TABLE #textfile
GO

I got target
-------------------------------
100140720102223470000103
200XXXX 000015000000010007000
200YY 000019000000010001600
200Z 000007000000010011200
3000000004100000

Why not the same ?

Sachin.Nand

2937 Posts

Posted - 2010-07-27 : 05:05:23
So what is the problem?


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-27 : 05:11:08
quote:
Originally posted by Zoran035

I have source file A.TXT
----------------------------------------------------
100140720102223470000103
200XXXX 000015000000010007000
200YY 000019000000010001600
200Z 000007000000010011200
3000000004100000

when do T-SQL
-- Create a table to hold the data
CREATE TABLE #textfile (line varchar(8000))
-- Read the text file into the temp table
BULK INSERT #textfile FROM 'c:\A.TXT'
GO
-- Now read it
SELECT * FROM #textfile
-- And then clean up
DROP TABLE #textfile
GO

I got target
-------------------------------
100140720102223470000103
200XXXX 000015000000010007000
200YY 000019000000010001600
200Z 000007000000010011200
3000000004100000

Why not the same ?



Looks the same to me ..


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Zoran035
Starting Member

5 Posts

Posted - 2010-07-27 : 05:25:51
Editor kill blanks in source
original is with 'M'
I have source file A.TXT
----------------------------------------------------
100140720102223470000103
200XXXXM000015000000010007000
200YYMMM000019000000010001600
200ZMMMM000007000000010011200
3000000004100000
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-07-27 : 05:56:39
"Editor kill blanks in source"

Not if you use Forum Codes as per the link to the left of the box you posted your message into.

Put [code] ... [/code] tags around your text

You've now posted a link to the file in a completely different thread which is only adding to the confusion, and that link http://www.simple-talk.com/community/forums/thread/93648.aspx looks exactly the same as the text you posted here - except that it looks like you've inserted some "-" and a different number on each line.

I will remove your other post to avoid confusion now I've duplicated the link here.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-07-27 : 05:58:33
I will use REPLY to your original which has the spaces intact to make a display version for anyone else who is interested

quote:
Originally posted by Zoran035


I have source file A.TXT

----------------------------------------------------
100140720102223470000103
200XXXX 000015000000010007000
200YY 000019000000010001600
200Z 000007000000010011200
3000000004100000


I got target

-------------------------------
100140720102223470000103
200XXXX 000015000000010007000
200YY 000019000000010001600
200Z 000007000000010011200
3000000004100000

Go to Top of Page

Zoran035
Starting Member

5 Posts

Posted - 2010-07-27 : 06:07:43
Thank you for correct my post.
I thing that my question is now clear
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-28 : 06:35:44
Are they really spaces?
If it has tab, it will be converted to a single sapce

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Zoran035
Starting Member

5 Posts

Posted - 2010-07-28 : 08:42:13
quote:
Originally posted by madhivanan

Are they really spaces?
If it has tab, it will be converted to a single sapce

Madhivanan

Failing to plan is Planning to fail



I make A.TXT ( A1.TXT ) file with NotePad editor
A.TXT with spaces, A1.TXT with tab. There is no different
Try
Go to Top of Page
   

- Advertisement -