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
 General SQL Server Forums
 New to SQL Server Administration
 How to load commas from csv file into sql table?

Author  Topic 

gandalf117
Starting Member

1 Post

Posted - 2009-07-04 : 09:19:57
What I want to do is to load everything from the cells in the csv document, including commas into an sql table. What sql statement should I use? Example:

csv document looks something like this:

321 Some text, some text, some text.
543 Some other text, some other text.
645 Some other text, some other text.

sql table where I want to load the above csv file:
create table tableName (id int(10), description varchar(40));

Normally this can be easily achieved with the following sql statement:
load data infile 'filePath' into table tableName fields terminated by ',' lines terminated by '\n';

but when there are commas among the text in the second column it produces the following sql mistake: Row 1 was truncated; it contained more data than there were input columns
It seems that every time the sql engine reads a comma from the csv it adds a new field, that shouldn't be added. Is there a sql command or a way to insert commas from csv (Comma Separated Values) file into a table?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-04 : 09:34:11
This is a MS SQL Server forum. For MYSQL, please try dbforums.com or forums.mysql.com. You will get better answer there


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -