locked
SQL 2014 - How to import all CSV files in a folder into a single table. RRS feed

  • Question

  • Hi,

    I'm very new to SQL and i'm trying to create a script that imports all CSV's from a folder into one table in management studio.

    All the tables are in the same structure and have a title column.

    Thanks in advance for your help.

    Akhil

    Tuesday, May 17, 2016 12:26 PM

Answers

All replies

  • Hi, 

    You can find the script here

    http://stackoverflow.com/questions/16076309/import-multiple-csv-files-to-sql-server-from-a-folder

    Thanks

    Tuesday, May 17, 2016 12:41 PM
  • Why script task when you have same structure?

    We can use ForEachLoop Container to import multiple CSV files in a folder.


    Regards, RSingh

    Tuesday, May 17, 2016 1:51 PM
    • Proposed as answer by Harry Bal Wednesday, May 18, 2016 3:53 PM
    • Marked as answer by Eric__Zhang Sunday, May 29, 2016 1:56 PM
    Tuesday, May 17, 2016 4:42 PM
  • Hi Akhil85,

    In addition, you can also use a Mutiple Flat Files Connection to achieve it in SSIS.(Reference the below pictures)


    If you have any other questions, please feel free to post.

    Regards,
    Seif Wang

    • Proposed as answer by Seif Wang Saturday, May 28, 2016 6:56 AM
    • Marked as answer by Eric__Zhang Sunday, May 29, 2016 1:56 PM
    Wednesday, May 18, 2016 2:47 AM
  • Thanks alot all, trying to work through and see which is best. 

    Forgive the complete beginner question but can you run SSIS package through management studio or does it have to be through an alternative such as visual studio. Or is visual studio the only program for this? 

    Thursday, May 19, 2016 2:28 PM
  • For some reason this script can't seem to find the files. In the ALLFILENAMES folder it says files not found. I have confirmed location and CSV type. I also set them to be in a c drive folder in case it couldn't find a network folder. Still didn't work. Do i need to set up a connection somehow?

    Thanks

    Thursday, May 19, 2016 2:48 PM