I have a bunch of Excel files that I want to import into a SQL Server database using a script.
I have imported one of the files (BasicCompanyData-2015-02-01-part1_5.csv) using the import wizard to setup the table correctly and then run the
delete * from dbo.temp
But when I run the following query I get the error:
Bulk load data conversion error(type mismatch or invalid character for
the specified codepage)
My SQL code:
BULK INSERT [UK DATABASE 2014].dbo.temp
FROM 'D:\The Data Warehouse.co.uk\BasicCompanyData-2015-02-01-part1_5.csv'
WITH
(
FIELDTERMINATOR=',',
ROWTERMINATOR='\n',
FIRSTROW=2
)
Any ideas for what I am doing wrong?
Related
I'm trying to import a very big .CSV file (about 2 GB) as a table into a database in SQL Server (through SQL Server Management Studio).
I tried doing it with the "Import Flat File..." and the "BULK Insert" in the query console as well, both take an extremely long time and I stopped the execution, or it just fails by itself at the end.
BULK INSERT [table name]
FROM 'Path of the CSV'
WITH (FIRSTROW = 1,
FIELDTERMINATOR = ',',
ROWTERMINATIR = '0x0A')
Maybe I'm doing something wrong?
I couldn't find any solution except splitting the data into smaller files but I wanted to avoid doing that.
Thank you.
I created an SSIS to load excel files. It loops through a specified folder for relevant files and reads the data in each file into a raw data table and then I have SQL scripts that does the validation and places the data in the relevant tables etc... and it all works fine.
but I now need make the ssis package handle loading excel files with 3 different file structures. ie one file will have 50 columns, one will have 55 and one will have 60.
I have tried using a script task to load the data
Insert into <rawdatatable> select * from openrowset('Microsoft.Jet.OLEDB.4.0','excel 8.0; database=D:\SSIS\FileToLoad.xlsx', 'Select * from [Sheet1$]')
but I keep getting the error below, but adding error logging doesn't give any other errors
Exception has been thrown by the target of an invocation
I am using SQL Server 2014 and VS 2013
I'm not really sure what I am doing here, any help or guidance would be appreciated
Thanks
You must use Microsoft.ACE.OLEDB.12.0 provider, try following:
Insert into <rawdatatable>
select * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=D:\SSIS\FileToLoad.xlsx;HDR=YES',
'SELECT * FROM [Sheet1$]')
References
Import/Export Excel (.Xlsx) or (.Xls) File into SQL Server
I want to know how to insert value in SQL Server database with the flat file source in SSIS using SQL command. I've done inserting it using table view, now i have to insert it using SQL command
Well you need a good query to set into a Execute SQL Task in SSIS
you can get help for queries in the site below
----here is the link ----
well you can parametrize the query in Execute SQl Task of SSIS
BCP
This is one of the options that is mostly widely used. One reason for this is that it has been around for awhile, so DBAs have come quite familiar with this command. This command allows you to both import and export data, but is primarily used for text data formats. In addition, this command is generally run from a Windows command prompt, but could also be called from a stored procedure by using xp_cmdshell or called from a SSIS package.
Here is a simple command for importing data from file C:\ImportData.txt into table dbo.ImportTest.
bcp dbo.ImportTest in 'C:\ImportData.txt' -T -SserverName\instanceName
BULK INSERT
This command is a T-SQL command that allows you to import data directly from within SQL Server by using T-SQL. This command imports data from file C:\ImportData.txt into table dbo.ImportTest.
BULK INSERT dbo.ImportTest
FROM 'C:\ImportData.txt'
WITH ( FIELDTERMINATOR =',', FIRSTROW = 2 )
Forgot to say that u can write a select query too with the samples in a OLEDB Source Using Sql Command
I'm trying to import a table from a txt file comma separated, the file was generated by the same SQL Server import/export assistant from my development database server.
Many tables has been imported by this way successfully.
The problem is when I have a column of the type date.
The message is: conversion unknown!
And then I cannot exec the package.
How can I solve this problem?
I have a CSV file with 10 columns. I want to import to SQL Server table with only 5 columns using powershell. Can anyone help in this ?
I suggest that Change your excel file to 5 sight column, and then using SQL Server Import\Export wizard or SSIS (if your convert is each day periodic) or PowerShell to convert your data.
You can you following reference in order to use PowerShell to convert your file:
SQL SERVER – Powershell – Importing CSV File Into Database