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)
 Using bcp to load CSV files

Author  Topic 

SteveR74
Starting Member

6 Posts

Posted - 2002-10-18 : 06:08:41
I am attempting to load csv files into SQLSERVER using the bcp utility(cannot use DTS), however i am having problems, I would appreciate it if some one could help me with the format file.

The fields are variable length, comma seperated.

Thanks,
Steve

smccreadie
Aged Yak Warrior

505 Posts

Posted - 2002-10-18 : 07:06:23
Did you try following examples in Books On-Line?

Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-10-18 : 07:38:00
Got quoted values? BCP can't handle them.


Go to Top of Page

SteveR74
Starting Member

6 Posts

Posted - 2002-10-18 : 12:58:22
Did you try following examples in Books On-Line? Yes

Got quoted values? BCP can't handle them No quoted values

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-10-18 : 13:26:43
OK, what kind of problems are you having? Can you post the structure of the table you're trying to import into? And a sample of the CSV file? (maybe 10 rows or so)

Could the CSV file have embedded commas in the data? If yes, can you change that file format to use tab or another character as a delimiter instead?

Go to Top of Page

SteveR74
Starting Member

6 Posts

Posted - 2002-10-20 : 08:13:48
I am having problems getting anything to load :). I used bcp to create the format file(is this wrong?) and it insists on putting in field lengths even though it picks up on the fact it is comma delimited?, I think this is where the problem occurs. I don't have any experience using bcp so please excuse my ignorance. The separator is not the problem.

thanks
Steve

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-10-20 : 08:19:28
The column length is normal, and using bcp to generate the format file is fine, I do it myself all the time. If the file is delimited bcp will ignore the length. Did you specify a comma as the column terminator? What did you put in for a row terminator?

Take a look in Books Online under "bcp format files", you might have to drill down through several articles, but there is an entry in there that lays out the structure of a format file and how it works. Look at the example, and then use it as a guideline to make sure your format file is correct. Usually the problem arises with the row terminator (\n by default), especially if your data file comes from a Unix source, because Unix has a different line terminator character than DOS/Windows does.

Also, if it's not importing, it must be throwing an error message, right? What message do you get?

Go to Top of Page

SteveR74
Starting Member

6 Posts

Posted - 2002-10-20 : 09:21:27
Thanks for your response robvolk, I did ftp the files over from the HP-UX box so I guess the line terminator is probably the issue.

Thanks,
Steve

Go to Top of Page
   

- Advertisement -