SQL Server 2005 - Bulk Insert failing -
i have txt file contains 1600 rows , 82 columns of comma delineated data trying import table. following error on every row on last field:
msg 4864, level 16, state 1, line 1 bulk load data conversion error (type mismatch or invalid character specified codepage) row 1, column 81 (db252d20c8).
the import statement is
bulk insert [energy].[dbo].[readings1] 'c:\readings2.txt' ( datafiletype='widechar', fieldterminator = ',', rowterminator = '\n' ) go
the table structure follows, top , bottom of script:
use [energy] go /****** object: table [dbo].[readings1] script date: 05/13/2013 20:00:30 ******/ set ansi_nulls on go set quoted_identifier on go create table [dbo].[readings1]( [dateandtime] [datetime] not null, [db240d4c7] [float] null, [db240d8c7] [float] null, [db240d12c7] [float] null, [db240d16c7] [float] null, [db252d12c8] [float] null, [db252d16c8] [float] null, [db252d20c8] [float] null, constraint [readings1datatimestamp] primary key clustered ( [dateandtime] asc )with (pad_index = off, ignore_dup_key = off) on [primary] ) on [primary]
the text file follows:
2013-02-19 00:00:00.000,6,945,1886,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,2040,6299,0,0,6,567,1248,0,0,251,8859,8655,0,0,10,316,1786,0,0,7,180,1206,0,0,1,16,56,0,0,368,18953,36949,0,0,null,null 2013-02-19 01:00:00.000,6,147,1886,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,1516,6299,0,0,3,115,1248,0,0,250,5077,8655,0,0,9,219,1786,0,0,5,147,1206,0,0,1,15,56,0,0,362,8907,36949,0,0,null,null
alright need alter statement after end of file use keepnulls
. informs sql server wish keep null values. it's trying convert null
string float column
. alter statment this.
bulk insert [energy].[dbo].[readings1] 'c:\readings2.txt' ( datafiletype='widechar', fieldterminator = ',', rowterminator = '\n', keepnulls ) go
there article on bol this. .
otherwise can build integration services package handle this. easy fast way import information flat file sources.
Comments
Post a Comment