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 2000 Forums
 Import/Export (DTS) and Replication (2000)
 import text file

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-10-02 : 07:32:15
abe writes "hi...
how to import text file to sql server db using asp

sample data :-

this is a text file
HCOMPANY NAME HOLDING0000000001000.5502C12345
D780110-03-55550000000000500.00C12345
D780110-03-44440000000000500.55C12345

import to 2 sql db
db1 - line 1 (first character is H) for header
result :
COMPANY NAME HOLDING,1000.55,02,cC12345

db2 - line 2 and 3 (first character is D) for detail
result :
780110-03-5555,500.00,C12345
780110-03-4444,500.55,C12345

pls help me..Thank's"

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-10-02 : 12:55:42
Why not use DTS or bcp for this? These allow you to do this very easily.

Tara
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-10-03 : 14:44:04
create table ##mytbl (s varchar(8000))
BULK INSERT ##mytbl from 'c:\myfile.txt' with (FIELDTERMINATOR='|')
select * from ##mytbl


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-10-03 : 15:11:36
This is the whole header and trailer thing again....

Load the whole thing in to 1 varchar(8000) column and use SUBSTRING to interogate the data and the move it in to your final table...



Brett

8-)

SELECT @@POST FROM Brain ORDER BY NewId()

That's correct! It's an AlphaNumeric!
Go to Top of Page

Mits
Starting Member

48 Posts

Posted - 2003-10-06 : 07:02:37
hi nr,
I have the similar kind of application. In my case i have the text file delimited by comma and also the table with Field name. how do i use bulk insert in my vb application.

thanks
Mits
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-10-06 : 12:35:38
Mits, when you use bulk insert command, the file must be on the SQL Server. Information about bulk insert can be found in SQL Server Books Online.

Tara
Go to Top of Page
   

- Advertisement -