Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008: BULK INSERT csv - is it possible to choose fields?

Tags:

sql

sql-server

I am doing:

BULK INSERT CSVTest FROM 'c:\csvtest.txt'
WITH
(FIELDTERMINATOR = ',',
 ROWTERMINATOR = '\n')
GO

--Check the content of the table.
SELECT *
FROM CSVTest
GO

--Drop the table to clean up database.
SELECT *
FROM CSVTest
GO

Is it possible to insert only specific fields FROM the csv?

like image 505
Alex Gordon Avatar asked Feb 26 '23 02:02

Alex Gordon


2 Answers

Alternatively, you can bulk insert into a view.

See also this question.

like image 98
littlegreen Avatar answered Mar 01 '23 03:03

littlegreen


You can do this using a format file. See: Using a Format File to Skip a Table Column and Using a Format File to Skip a Data Field.

like image 28
Joe Stefanelli Avatar answered Mar 01 '23 03:03

Joe Stefanelli