Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing a text File into database

Status
Not open for further replies.

WolverineLogan

Programmer
Oct 9, 2001
29
0
0
ZA
Hi All

Been trying to import an ordinary text file containing AccountNo's into our SQL Server 2000 database from the query
analyser.
Can anyone show me how to use the BCP utility ?
Could you give an example to please ?

Thanks
 
Dear WolverineLogan

Take a look at this code, I import data from a text file the column delimiter is a pipe "|" and the rowdelimiter is "\n".

Create Table #Temp
( ClientName varchar(25) NULL ,
CategoryName varchar(15) NULL ,
InventoryNumber varchar(20) NULL ,
CustomerRefNo varchar(20) Null ,
Description varchar(255) Null ,
Descriptor varchar(50) NULL ,
Weight decimal(5, 0) Null ,
Height decimal(5, 0) NULL ,
Width decimal(5, 0) NULL ,
Depth decimal(5, 0) NULL ,
Comments varchar(500) Null )

-- Bulk copy the text file data into a table.
Select @SQL = 'Bulk Insert #Temp '
Select @SQL = @SQL + 'From ''' + @FileName + ''' '
Select @SQL = @SQL + 'With ( FIELDTERMINATOR = ''|'' , ROWTERMINATOR = ''\n'' , KEEPNULLS )'

Exec (@SQL)

Hope this helps...

Bye
Mahesh
mshetti@yahoo.com
 
... or you could use DTS in EM This is not a bug - it's an undocumented feature...
;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top