Is it possible to select certain columns from a .CSV file to SQL table using BCP? If so how? I need to import only 5 columns from a flat file that I get with more than 10 columns, how do i choose the only 5 column I need from such csv file. Please help.
(comments are locked)
|
Yes, take a look at the format file. That allows you to map the data in the file to columns in the database.
(comments are locked)
|
Why don't you use SSIS? That will be lots easier then BCP (Bulk Copy Program).
(comments are locked)
|
Grant has the right answer to the question directly asked, but I think Leo probably is suggesting the best answer (+1 to both). BCP is probably the easiest and best way to handle this task (barring some reason to prefer BCP not listed in the question.) Just for the sake of completeness, let me point out you can do this using pure T-SQL using OpenDatasource. There is some information that might be useful in doing that at: http://www.sqlservercentral.com/articles/OpenDataSource/61552/
(comments are locked)
|
Can't let this question go by without mentioning LogParser, it would let you specify the columns that you want by name, change the data types if necessary, rename the columns in pass it in to SQL in one query. It would be my preference. Leo, Grant and Timothy have valid, workable solution though. +1's all round :)
(comments are locked)
|