• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

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
0
JElster
Asked:
JElster
  • 2
3 Solutions
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now