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)
 Bulk Insert / bcp format file

Author  Topic 

sameerv
Starting Member

29 Posts

Posted - 2002-07-24 : 02:04:18
Hi Guys,
I need a solution to my problem urgently.
My Problems is in importing data from a text file to a SQL 7.0 table.

I have a text file named textsample.txt with 3 fields :
Bank ID (varchar(15))
Bank Name (varchar(100))
Bank Status (char(1)- Y/N)

I have a table named BankDetails with 5 fields:
BankID (varchar(15))
BankName (varchar(100))
BankStatus (char(1)- Y/N)
BkLastTransaction (smalldatetime)-nullable
BankActive (char(1)- Y/N)-nullable

I have to import data from the text file to the first 3 fields of the table.
Using Bulk Insert without a bcp format file gives me an error, presumably because the number of columns differ.
Please give me the procedure for creating a bcp file format for the above structure.

Also, I have created a DTS package for the above transfer but I am unable to use it.
If possible, please show me how to call this package from
a.) a stored procedure
b.) an asp form

NOTE : the text file and the database reside on different servers.


robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-07-24 : 07:54:18
Something like this should work:

8.0
5
1 SQLCHAR 0 15 "," 1 BankID SQL_Latin1_General_Cp437_BIN
2 SQLCHAR 0 100 "," 2 BankName SQL_Latin1_General_Cp437_BIN
3 SQLCHAR 0 20 "\r\n" 3 BankStatus SQL_Latin1_General_Cp437_BIN
4 SQLCHAR 0 0 "" 4 BkLastTransaction SQL_Latin1_General_Cp437_BIN
5 SQLCHAR 0 0 "" 5 BankActive SQL_Latin1_General_Cp437_BIN

Copy and past the above into a text file with the proper name and .fmt extension and test it with bcp or BULK INSERT. If it does not work, look in Books Online under format files, there are several examples that detail how to use it with mismatching columns, you can adjust the file accordingly until it does work.

Go to Top of Page
   

- Advertisement -