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 2012 Forums
 Transact-SQL (2012)
 Bulk insert data conversion error

Author  Topic 

kotonikak
Yak Posting Veteran

92 Posts

Posted - 2014-11-03 : 17:15:59
I'm trying to create a table in SQL and bulk insert a text file.

create table dbo.ADM_County_YTD
(
[Record Type Code] varchar(6),
[Record Category Code] varchar(2),
[Reinsurance Year] int,
[State Code] varchar(2),
[County Code] varchar(3),
[County Name] char(25),
[Last Released Date] date,
[Deleted Date] date,
);

BULK insert dbo.ADM_County_YTD
from '\\...\2015_A00440_County_YTD.txt'
with (fieldterminator='|', rowterminator='\n',FIRSTROW = 2)


I get the following errors:

Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 8 (Deleted Date).
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 53
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)"


I'm trying to fix the conversion error first. Here is the actual Data for row 2:

Record Type Code|Record Category Code|Reinsurance Year|State Code|County Code|County Name|Last Released Date|Released Date|Deleted Date
A00440|01|2015|01|001|Autauga||20140403|


Not sure if the date format is off or if it's catching some other problem.
Any help will be appreciated!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-03 : 17:22:21
Try changing the table structure to use all varchars. That's the easiest way to get data in, then you can move the data to the proper form. This is known as a staging table.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

kotonikak
Yak Posting Veteran

92 Posts

Posted - 2014-11-03 : 17:29:23
If I change the date formats to varchar(8), I get the following truncation error:
 Msg 4863, Level 16, State 1, Line 53
Bulk load data conversion error (truncation) for row 2, column 8 (Deleted Date).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-03 : 17:31:23
Try removing the last | as that indicates there's another field.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -