BULK INSERT to specific columns?

I want to embed the columns of the CSV file into specific columns of the destination table. Description - the destination table contains more columns than my csv file. So, I want the columns of the csv file to fall into the desired target columns using BULK INSERT.

Is it possible? If so, how to do it?

I saw the tutorial and code on the page 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 /

and http://www.codeproject.com/Articles/439843/Handling-BULK-Data-insert-from-CSV-to-SQL-Server

BULK INSERT dbo.TableForBulkData FROM 'C:\BulkDataFile.csv' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) 

They do not show how you can control where the data was inserted.

+7
sql sql-server sql-server-2005 bulkinsert
source share
1 answer

Yes you can do it. The easiest way is to simply create a view from Select from the target table, which lists the columns to which the data should be sent, in the order they appear in the source file. Then BULK INSERT in your view instead of directly into the table.

+8
source share

All Articles