SQL Server - Import multiple CSV files

Posted on 2012-09-18
Last Modified: 2012-09-18
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.
Question by:JElster
    LVL 13

    Assisted Solution

    LVL 41

    Accepted Solution

    Check this

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

    Assisted Solution

    by:Saurabh Bhadauria
    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

    and then import each file in a loop .
     Link mentioned in above post will help you out on this ..
    LVL 41

    Expert Comment

    mind you that LIONKING solution is not what you're looking for, since that only considers one file, not multiple ones.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I recently came across an interesting Question In EE ( and was puzzled about how to achieve that using SSIS out of the box tasks, which was i…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now