I have some financial data in a CSV
file and I would like to put it into an SQL table.
I want to run the following script which I adapted from this source :(http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/)
CREATE TABLE Price
(ID INT IDENTITY(1,1) NOT NULL,
PriceDate datetime2,
OpenPrice decimal(10,4),
HighPrice decimal(10,4),
LowPrice decimal(10,4),
ClosePrice decimal(10,4),
Volume int,
AdjClose decimal(10,4),
AdjOpen decimal(10,4),
AdjLow decimal(10,4),
AdjHigh decimal(10,4)
)
GO
BULK
INSERT Price
FROM 'C:\Users\Public\Documents\bhp.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
I am getting the following errors:
'Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 1 (ID).'
I think, it is because my "ID
" which is a primary key and an autonumber increment.
Obviously I don't want to be generating this number via the CSV (I plan to insert multiple CSV files into this table later), I want it generated by the database.
Is it possible to specify to BULK INSERT
which columns I plan to insert into for each column?