I am getting error when I am trying to do bulk insert:
BULK INSERT #tbl_InterCompanyUploadDetail_Staging
FROM '\\SVRP03546008461D\QA\UploadTemplatewithvalidation.xlsx'
WITH (FIRSTROW = 6, FIELDTERMINATOR ='\t', ROWTERMINATOR ='\\n' )
Error that I am getting is :
Bulk load data conversion error (truncation) for row 6, column 2 (Oracle Company Code).
The column in Excel has data as 470 and in database column is varchar (10). So what could be the reason for the error.
When you Bulk Insert the file without specifying or with specifying batch Size , 8 out of 10 get inserted into the table. The Invalid Row's i.e. 8th and 7th gets failed and doesn't get inserted. This Happens because the Default MAXERRORS count is 10 per transaction. Hope this solves the issue.
BULK INSERT statement BULK INSERT loads data from a data file into a table. This functionality is similar to that provided by the in option of the bcp command; however, the data file is read by the SQL Server process. For a description of the BULK INSERT syntax, see BULK INSERT (Transact-SQL).
Below are some good ways to improve BULK INSERT operations : Using TABLOCK as query hint. Dropping Indexes during Bulk Load operation and then once it is completed then recreating them. Changing the Recovery model of database to be BULK_LOGGED during the load operation.
BULK INSERT
may not work with xlsx files, try converting the .xlsx
file to .csv
file to achieve this (using BULK INSERT
)
Try using OPENROWSET
with Microsoft.ACE.OLEDB.12.0
provider:
Insert into <rawdatatable>
select * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=D:\SSIS\FileToLoad.xlsx;HDR=YES',
'SELECT * FROM [Sheet1$]')
OR
SELECT * INTO Data_dq
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0; Database=D:\Desktop\Data.xlsx', [Sheet1$]);
SELECT * INTO Data_dq
FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0',
'Data Source=D:\Desktop\Data.xlsx;Extended Properties=Excel 12.0')...[Sheet1$];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With