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
 Site Related Forums
 Article Discussion
 Import CSV file

Author  Topic 

jwaz1999
Starting Member

12 Posts

Posted - 2010-09-10 : 12:44:58
Is there a way that a CSV file can be imported into a SQL Server table using BCP if the file has the below 5 column format, or do you have to iterate through it one record at a time?

sample data:

5, "test, column", "test column 2", 4, "test column, 5"

6, test column", "test column 2,", 5, "test column 5"

7, test column", "test column 2", 6, "test, column 5"


If it can be done with BCP, how do you define the format for columns with quotes(char data) and columns without quotes(int data)?

Thanks,
Jeff

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-10 : 12:59:09
No quotes

commas have always been a problem

So is TAB

So is Pipe (|)

Can you do a multivalued delimiter?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

jwaz1999
Starting Member

12 Posts

Posted - 2010-09-10 : 13:16:16
Hi Brett,

This is universally accepted way to create a csv file. Check out:
http://en.wikipedia.org/wiki/Comma-separated_values

Quotes are used for character columns, and no quotes are used for integer columns. This way, if the data contains a comma or a double quote, the consuming user will know how to handle it. It makes sense to use this format.

Jeff

quote:
Originally posted by X002548

No quotes

commas have always been a problem

So is TAB

So is Pipe (|)

Can you do a multivalued delimiter?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam





Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-10 : 13:25:24
quote:
Originally posted by jwaz1999

Hi Brett,

This is universally accepted way to create a csv file. Check out:
http://en.wikipedia.org/wiki/Comma-separated_values




Well good for you with that.

Good Luck



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

jwaz1999
Starting Member

12 Posts

Posted - 2010-09-10 : 13:26:34
What do you mean good for me with that? I was just pointing a the "correct" way to create a CSV file? You didn't answer my question.

quote:
Originally posted by X002548

quote:
Originally posted by jwaz1999

Hi Brett,

This is universally accepted way to create a csv file. Check out:
http://en.wikipedia.org/wiki/Comma-separated_values




Well good for you with that.

Good Luck



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam





Go to Top of Page
   

- Advertisement -