SQL Server - Import multiple CSV files

Hi..
I have a folder of 50 CSV files.. Same layout.
How can I write a SP that will read all the CSVs from a folder and insert them into a single table.
thx
LVL 1
JElsterAsked:
Who is Participating?
 
ralmadaCommented:
Check this

you could consider creating a stored procedure, check the below:

http://www.databasejournal.com/features/mssql/article.php/3325701/Import-multiple-Files-to-SQL-Server-using-T-SQL.htm
0
 
Saurabh BhadauriaCommented:
Best approach will be to user SSIS package.
Stil you want to do it through SP then first you need to list all the files using xp_cmdshell
and then load them one by one in a loop.

you can check below link to list down all the files

http://www.sqlusa.com/bestpractices2008/list-files-in-directory/ 

and then import each file in a loop .
 Link mentioned in above post will help you out on this ..
0
 
ralmadaCommented:
mind you that LIONKING solution is not what you're looking for, since that only considers one file, not multiple ones.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.