Bulk Insert doesn't insert any rows

Peter Evjan picture Peter Evjan · Jul 10, 2012 · Viewed 8k times · Source

I am importing data from CSV files into temp tables before merging them with a "real" table.

For my other tables, this works fine. But for this one particular file and table, nothing seems to happen.

CREATE TABLE #ManifestHeader (  
[ROTATIONNUMBER] [nvarchar](12) NOT NULL,
[ROTATIONVERSIONNO] [nvarchar](2) NOT NULL,
[IMONUM] [nvarchar](50) NULL,
[VESSELNAME] [nvarchar](35) NOT NULL,
[VOYAGENO] [nvarchar](17) NOT NULL,
[CARRIERCODE] [nvarchar](10) NULL,
[CARRIERNAME] [nvarchar](35) NULL,
[ETA] [datetime] NULL,
[ETD] [datetime] NULL,
[ACTUALARRIVALDATE] [datetime] NULL,
[LASTPORTOFCALL] [nvarchar](5) NULL,
[PORTARRIVAL] [nvarchar](5) NULL,
[PORTNEXT] [nvarchar](5) NULL,
[PORTFINAL] [nvarchar](5) NULL,    
[BERTHINGDATE] [datetime] NULL,
[CDRSTARTDATE] [datetime] NULL,
[CDRENDDATE] [datetime] NULL,
[CDRSUBMISSIONDATE] [datetime] NULL,
[NUMOFBOLS] [int] NULL,
)

BULK INSERT #ManifestHeader
FROM 'D:\csvfiles\ManifestHeader.csv'
WITH ( FIELDTERMINATOR = '<,>', ROWTERMINATOR = '\n', FIRSTROW = 2, KEEPIDENTITY );

SELECT * FROM #ManifestHeader;

The last select statement returns nothing and no errors are shown.

The CSV file contains thousands of lines. Example lines:

ROTATIONNUMBER<,>ROTATIONVERSIONNO<,>IMONUM<,>VESSELNAME<,>VOYAGENO<,>CARRIERCODE<,>CARRIERNAME<,>ETA<,>ETD<,>ACTUALARRIVALDATE<,>LASTPORTOFCALL<,>PORTARRIVAL<,>PORTNEXT<,>PORTFINAL<,>BERTHINGDATE<,>CDRSTARTDATE<,>CDRENDDATE<,>CDRSUBMISSIONDATE<,>NUMOFBOLS
12345678911<,>1<,>VB3BV<,>BLACKSTONE<,>020<,>MUNICA<,>MUNICA<,>2012-05-08 10:32:00<,>2012-05-08 11:32:00<,>2012-05-09 07:15:00<,>SGSIN<,>MZZPZ<,>MZZBW<,>MZZBW<,><,>2012-05-09 07:22:00<,><,>2012-05-09 07:22:26<,>1
12345678912<,>1<,>VB4BV<,>REDSTONE<,>021<,>MUNICA<,>MUNICA<,>2011-11-29 11:48:00<,>2011-11-30 11:48:00<,><,>ZADER<,>MZZPZ<,>ZARCB<,>MZZPZ<,><,><,><,><,>
12345678913<,>1<,>VB5BV<,>BLUESTONE<,>022<,>MUNICA<,>MUNICA<,>2012-05-09 08:00:00<,>2012-05-10 10:39:00<,>2012-05-09 11:11:00<,>ZADER<,>MZZPZ<,>ZARCB<,>ITCVV<,><,>2012-05-09 15:00:00<,><,>2012-05-07 11:14:42<,>1
12345678914<,>1<,>VB6BV<,>GREENSTONE<,>023<,>MUNICA<,>MUNICA<,>2012-05-29 07:00:00<,>2012-05-29 23:00:00<,>2012-05-29 09:12:00<,>LKCMB<,>MZMNC<,>MZMNC<,>SGSIN<,><,>2012-05-29 23:00:00<,>2012-05-30 12:00:00<,>2012-05-29 09:30:33<,>1

What could I be missing here?

Answer

Peter Evjan picture Peter Evjan · Jul 11, 2012

Ed Harper led me in the right direction: the row terminator was wrong.

So when I changed it to

ROWTERMINATOR = '0x0a' 

in BULK INSERT (instead of '\n') it started working.