As the title says, I am attempting to insert a CSV into a temporary table. I am unfortunately encountering errors.
Here is the query:
USE DATABASE5000
CREATE TABLE #tempTable1
(
ID INT,
CD VARCHAR(50),
ESD DATETIME,
EED DATETIME,
MiscDate DATETIME,
SQ SMALLINT
)
BULK INSERT #tempTable1
FROM 'C:\Dir\Folder\BestFile.csv';
And here are the errors I get:
Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.Msg 7399, Level 16, State 1, Line 1
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 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
Any ideas? Thanks yall.
You can verify in the tempdb database that the table is created with the data that was stored in the CSV file. In this way, you can bulk insert data into a temp table in SQL Server. You may face some scenarios where you have an identity column in your table. If you try to bulk insert data into that table, new identity values will be assigned.
Sometimes there is a scenario when we have to perform bulk insert data from .csv files into SQL Server database. We can use the GUI interface in SSMS (SQL Server Management Studio) to import data from Excel, CSV, etc files.
You can import data from a CSV file into a new table using this Wizard. The SQL Server Import and Export Wizard will create a table and import data into it. In SQL Server Import and Export Wizard, you have to select the data source as Flat File Source and select the CSV file. Also, you have to specify the format of the CSV file at this step.
You can see that all the 15 rows from the CSV file are inserted into the dbo.Persons table. Hence, in this way, you can skip the headers in your CSV file while importing data from this file into a table using the BULK INSERT statement in SQL Server.
You didn't specified any FIELDTERMINATOR
. The default value is actually tab
. Please refer to BULK INSERT documentation.
BULK INSERT #tempTable1
FROM 'C:\Dir\Folder\BestFile.csv'
WITH
(
FIELDTERMINATOR = ',' -- add this
);
According to documentation, there is a FORMAT = CSV
WITH (FORMAT = 'CSV')
You may try that. I did a quick test, there are some limitations it seems like does not support string with double quote in it
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