Solved

multiple csv to distinct tables - Import to sqlserver

Posted on 2014-03-05
10
333 Views
Last Modified: 2016-02-10
Hello All,

I spent a good time on learning SSIS for each to  loop through multiple files and then insert those into 1 table in sql server. But my main goal is to import those multiple csv into their own dest tables in the server. How do i leverage or edit the for each to do this accordingly?

Thank you
0
Comment
Question by:Rayne
  • 6
  • 2
  • 2
10 Comments
 

Author Comment

by:Rayne
ID: 39905819
so import different csv files to different tables so to speak...how?
0
 

Author Comment

by:Rayne
ID: 39905957
found these two
http://www.sqlservercentral.com/Forums/Topic1198006-147-1.aspx
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/a3e3273c-2c90-4d7b-91de-00f0569ecfb6/multiple-flat-file-i

but still i am confused how can i do those ways? or any other way....i am stumped. This is a work stopper :( for me
0
 

Author Comment

by:Rayne
ID: 39905960
further, with regards to Bulk insert - this acts weird even if I do just a single sql statement for it - says file cannot be opened or found - i do have all admin access to all folders...so this bulk insert doesn't work for me for some reason
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:Rayne
ID: 39905976
i know how to loop through files and import into one table using ssis - the only thing if using some magic i can add a condition like
before the row insertion happens from source, if src1 then desttbl1,if src2 then desttbl2
something like that - as it loops through the files, it knows where to import that current file data to ....
0
 

Author Comment

by:Rayne
ID: 39905977
stumped
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39908161
Hi Rayne,

The only thing extra that you would need to add is to make the connection string an expression.  Change your table to a new table and you should be good to go.  Ensure your DelayValidation is on for that step or it won't compile.

I found this which gives you the basic formula for the connection string:
http://social.technet.microsoft.com/Forums/sqlserver/en-US/8c2cf0ab-0701-49d8-ac25-4990051dd517/dynamic-connection-string-for-oledb-connection-string-in-ssis?forum=sqlintegrationservices
0
 
LVL 37

Accepted Solution

by:
ValentinoV earned 500 total points
ID: 39908891
Kyle: unless I misunderstood the question I don't think making the connection string dynamic will help here.  It's the table name (in other words the Data Flow Transformation destination) that needs to be dynamic.

And that can be done too.  The following assumes a Data Flow Transformation is used to load the CSV with an OLE DB Destination.

The OLE DB Destination properties contain a dropdown called Name of the table or view.  One of the options here is Table name or view name variable. This allows you to select a package variable that contains the name of the table.

And package variables can be made dynamic setting the EvaluateAsExpression property to True and specifying an expression in the Expression property.  That's just one method of making a variable dynamic btw.  In this case perhaps it's more interesting to configure the different file/table combos in a SQL Server table and then use an Execute SQL Task in the Foreach Loop to load the variable dependent on the current file in process...
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39909533
Yeah, don't mind me, was up late waiting for a query to run and lurking on EE.  Please disregard the last comment of mine.
0
 

Author Closing Comment

by:Rayne
ID: 39911874
thank you :)
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 39911905
Sure, glad to have been of assistance! :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A couple of weeks ago, my client requested me to implement a SSIS package that allows them to download their files from a FTP server and archives them. Microsoft SSIS is the powerful tool which allows us to proceed multiple files at same time even w…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

821 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