Solved

multiple csv to distinct tables - Import to sqlserver

Posted on 2014-03-05
10
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

739 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