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 of comma delimited text file

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-12-17 : 06:43:33
Roger writes "Hi,

What is the best way to read a comma delimited text file which does not have a fixed number of input columns? I am using bulk insert which works fine when there is a fixed number of input columns in the input text file. But, in cases where some records in the input text file have less input columns then others, the bulk insert command starts loading the extra columns from the next record. I have specified the record terminator field (which should be a carrage return) but it still does not work. Otherwise should I use BCP if BCP will allow for variable number of input fields?

I am using:
with (fieldterminator = ''","'', rowterminator = ''\n'', keepnulls, tablock)

Thanks,
Roger"

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2004-12-22 : 11:49:00
Use DTS and set the transformation dinamically by using script depend on how many field exist in your text file. Can this help ?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-22 : 12:02:54
Import into a staging table then parse it from there.
This will impor tthe file when it turns up
http://www.nigelrivett.net/ImportTextFiles.html

For MergeBCPData
you could have something that uses
http://www.nigelrivett.net/f_GetEntryDelimiitted.html
Although it migt be slow for a large volume.

==========================================
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
   

- Advertisement -