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 2005 Forums
 Transact-SQL (2005)
 Import data

Author  Topic 

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 2009-07-23 : 18:04:13
bulk insert dbo.IMPORT_DATA
from 'c:\Myfile.csv'
with (FIRSTROW=2,FIELDTERMINATOR='","',ROWTERMINATOR = '
')

Data is
DATETIME, COL2, COL3
"7/22/09 9:39 AM","2.85E-05","7.45E-05"
"7/22/09 9:39 AM","0","0.017333333"
"7/22/09 9:40 AM","0","0.008008342"

It brings it in with the " "

Any ideas to get rid of the ""

Cheers

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-23 : 21:33:33
[code]
update IMPORT_DATA
set <col name> = replace( <col name> , '"', '')
[/code]


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

Go to Top of Page

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 2009-07-23 : 22:42:31
I was hoping not to do update afterwards as so many columns in table 130 ....and millions of rows.

Hmmm
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-23 : 22:57:42
all the value is enclosed in double quote " " ?

try use "," as delimiter


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

Go to Top of Page

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 2009-07-23 : 23:03:19
Thanks i give it a try
Go to Top of Page

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 2009-07-24 : 11:13:38
Got it working. Found this.

So only first column and last has the " on it so i just do update on this part. Cheers
http://www.sqlteam.com/article/using-bulk-insert-to-load-a-text-file

Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2009-07-26 : 12:59:43
If you use a good and proper BCP format file, you won't even need to do that.

--Jeff Moden
"Your lack of planning DOES constitute an emergency on my part... SO PLAN BETTER! "
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row"

Go to Top of Page
   

- Advertisement -