SSIS packege to load CSV file in new sql table every time it runs.

Kavitha Chandra 96 Reputation points
2021-02-24T22:00:35.727+00:00

Hello, I am new to SSIS.I need to create a SSIS package where CSV is the source file and SQL table is the destination. Users place CSV file once in a week, for every run (on a weekly basis) it needs to create a new dynamic SQL table in DB.Table name will date extension along with the file name. Can any one help me with the steps to achieve this? Thanks in advance,

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,449 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Monalv-MSFT 5,891 Reputation points
    2021-02-25T03:30:16.187+00:00

    Hi @Kavitha Chandra ,

    May I know if the CSV files have same structions( same columns and same datatypes)?

    If yes, we can use Foreach Loop Container to foreach the CSV files, use Execute SQL Task to create new sql tables and use Data Flow Task to load data from CSV files to sql tables.

    We should execute the Foreach Loop Container and the Execute SQL Task firstly.
    And then execute the Foreach Loop Container and the Data Flow Task after disabling Execute SQL Task.

    Please refer to the following pictures:
    71941-testfiles.png
    71906-execute1.png
    71838-execute2.png
    71879-cmandvariables.png
    Variable SqlQuery-Expression:
    "CREATE TABLE "+ @[User::TableName] +" (
    [Column 0] varchar(50),
    [Column 1] varchar(50),
    [Column 2] varchar(50),
    [Column 3] varchar(50),
    [Column 4] varchar(50),
    [Column 5] varchar(50)
    )"
    Variable TableName Expression:
    "["+TOKEN(TOKEN( @[User::FileName] ,"\", 7 ), ".", 1 )+"_"+ (DT_WSTR, 50) @[User::Date]+"]"
    71820-flc-collection.png
    71932-est.png
    71908-dft-oledbdestination.png
    71886-ffcm-expression-connectionstring.png

    The following links will be helpful:
    1.Creating dynamically generated CSV files containing SQL Server data
    2.Import Text and CSV Files into SQL Server Database with SSIS Script Task

    Best regards,
    Mona

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.