Answered by:
How to load the data from CSV file in temp table at run time?

Question
-
Hi -
I want to know how I can load the CSV file data into the sql server table. I know there are ways like bulk insert and other to load the csv file data into the table. But in my case the table doesn't exist and has to be created at the run time.
With simple insert in temp table we do like
select * into #temp from tablename
and that creates the temp table. So. I need something like that which create the temp table and load the data into it. because the CSV file would have different number of columns and names so I can not create the table structure in advance. I have to create the table at run time.
Please let me know how I can do this.
THanks,
- Edited by Incredible15 Thursday, May 28, 2015 2:02 PM
Thursday, May 28, 2015 2:01 PM
Answers
-
Just search on Internet, you will find a lot of examples, e.g.:
http://bradsruminations.blogspot.de/2011/01/so-you-want-to-read-csv-files-huh.html
Olaf Helper
[ Blog] [ Xing] [ MVP]- Proposed as answer by Eric__Zhang Friday, May 29, 2015 6:04 AM
- Marked as answer by Eric__Zhang Monday, June 8, 2015 5:33 AM
Thursday, May 28, 2015 4:59 PM
All replies
-
Hello,
You can use the OPENROWSET (Transact-SQL) function to read CSV file, then you can transform the data in the SELECT and you can insert the data into any table, also into a temp table.
Olaf Helper
[ Blog] [ Xing] [ MVP]Thursday, May 28, 2015 2:39 PM -
Do you have some sort of example to do that? If you have one then It would be so much help
Thanks,
Thursday, May 28, 2015 3:35 PM -
Just search on Internet, you will find a lot of examples, e.g.:
http://bradsruminations.blogspot.de/2011/01/so-you-want-to-read-csv-files-huh.html
Olaf Helper
[ Blog] [ Xing] [ MVP]- Proposed as answer by Eric__Zhang Friday, May 29, 2015 6:04 AM
- Marked as answer by Eric__Zhang Monday, June 8, 2015 5:33 AM
Thursday, May 28, 2015 4:59 PM