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)
 Bulk Insert CSV Files

Author  Topic 

tpavan7329
Starting Member

18 Posts

Posted - 2011-08-04 : 00:05:41
I have a task import csv file into a table using bulk insert.

CSV has records something like this

"User_ID","User_Nickname","User_Registration_Date","User_Country","Game_Id","Game_Name","Session_start_time","Session_End_time","User_Device_ID","User_Device_Type","User_Device_OS","sessionstat_id"
4349,"norx1","2010-12-07 20:05:29","UA",2000,"Poker","2011-07-30 08:08:02","2011-07-30 08:16:43","d4eb4d008bc0241d46baass57bf6d475a9d","iPhone/iPod/iPad","iPhone OS",1006412558
4364,"Asdfg","2010-12-08 10:23:48","KW",2000,"Poker","2011-07-30 06:16:41","2011-07-30 06:29:38","76401fe7ae00d6301628e33fdghcaa916d43","iPhone/iPod/iPad","iPhone OS",1056811020



SQL Script:
BULK INSERT core_reporting.dbo.PPS_SessionReport_CCBulkTest FROM 'C:\report_2011_07_12_2000.csv'
WITH
(
FIRSTROW=2,
FORMATFILE='D:\Test\formatfile.fmt'
)


Format File:

1 SQLCHAR 0 50 "\," 0 UserId SQL_Latin1_General_Cp437_BIN
2 SQLCHAR 0 255 "\",\"" 1 UserNickName SQL_Latin1_General_Cp437_BIN
3 SQLCHAR 0 100 "\",\"" 2 UserRegistrationDate SQL_Latin1_General_Cp437_BIN
4 SQLCHAR 0 50 "\",\"" 3 UserCountry SQL_Latin1_General_Cp437_BIN
5 SQLCHAR 0 50 "\," 4 GameId SQL_Latin1_General_Cp437_BIN
6 SQLCHAR 0 255 "\",\"" 5 GameName SQL_Latin1_General_Cp437_BIN
7 SQLCHAR 0 100 "\",\"" 6 SessionStartTime SQL_Latin1_General_Cp437_BIN
8 SQLCHAR 0 100 "\",\"" 7 SessionEndTime SQL_Latin1_General_Cp437_BIN
9 SQLCHAR 0 255 "\",\"" 8 UserDeviceID SQL_Latin1_General_Cp437_BIN
10 SQLCHAR 0 50 "\",\"" 9 UserDeviceType SQL_Latin1_General_Cp437_BIN
11 SQLCHAR 0 50 "\",\"" 10 UserDeviceOS SQL_Latin1_General_Cp437_BIN
12 SQLCHAR 0 50 "\r\n" 11 SessionStatID SQL_Latin1_General_Cp437_BIN


I get below error message

Msg 9422, Level 16, State 48, Line 1
XML parsing: line 2, character 0, incorrect document syntax

Can anyone help me to figure out what the issue here is?


T Pavan Kumar
   

- Advertisement -