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.
Author |
Topic |
anxcomp
Starting Member
41 Posts |
Posted - 2007-09-04 : 13:53:02
|
Hi,Simple table:TABLE:create table employee ( name char(20), title char(120))DATAFILE(.csv):name;titleGustavo;"Marketing Assistant"Catherine;"Engineering Manager"I'd like use BULK INSERT command to insert this data. Tell me please,how should look formatfile (.fmt) for this example (SQL 2005). I needdata after BULK INSERT looks like this:name title-------------------- ---------------------Gustavo Marketing AssistantCatherine Engineering ManagerNOT like this:name title-------------------- ----------------------Gustavo "Marketing Assistant"Catherine "Engineering Manager"So, " should be escape.Thank you--Regards,anxcomp |
|
anxcomp
Starting Member
41 Posts |
Posted - 2007-09-06 : 15:25:14
|
Hello,I've done this, it's almost finished. You can tray this:/***************************************************************************************************/--tableCREATE TABLE [dbo].[ImportTest]( [fname] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL, [lname] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL, [organization] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL, [address] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL, [zip] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL, [city] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL, [state] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL, [email] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL) ON [PRIMARY]--data file (ImportTest.csv), REMEMBER at the end you HAVE TO add ENTERfname;lname;organization;address;zip;city;state;email;Shirley;Birosik;;;90013;"Los Angeles";"CA";"sbirosik@gmail.com";Dennis;Eschen;;;94920;"Alhambra";"CA";"de@hotmail.com";Valerie;Chambers;;;91803;"Long Beach";"CA";"vweber@verizon.net";--fmt file(ImportTest.Fmt), add ENTER at the end9.081 SQLCHAR 0 510 ";" 1 fname Latin1_General_CI_AS2 SQLCHAR 0 510 ";" 2 lname Latin1_General_CI_AS3 SQLCHAR 0 510 ";" 3 organization Latin1_General_CI_AS4 SQLCHAR 0 510 ";" 4 address Latin1_General_CI_AS5 SQLCHAR 0 510 ";\"" 5 zip Latin1_General_CI_AS6 SQLCHAR 0 510 "\";\"" 6 city Latin1_General_CI_AS7 SQLCHAR 0 510 "\";\"" 7 state Latin1_General_CI_AS8 SQLCHAR 0 510 "\r\n" 8 email Latin1_General_CI_ASbulk insert ImportTestfrom 'd:\bulk\ImportTest.csv'with ( formatfile = 'd:\bulk\ImportTest.Fmt', firstrow = 2)--(2 row(s) affected)select*from ImportTestDennis Eschen NULL NULL 94920 Alhambra CA de@hotmail.com";Valerie Chambers NULL NULL 91803 Long Beach CA vweber@verizon.net";/***************************************************************************************************/For me now most important is why didn't insert first row (data row, not column definition)?When I added quotation mark to column definition works fine, but I can't modify .csv file, I received it from third part company :( is it possible add all rows without modification .csv file?Second, how remove quotation mark and semicolon from last column?--Regards,anxcomp |
|
|
|
|
|
|
|