Solved

multiple csv to distinct tables - Import to sqlserver

Posted on 2014-03-05
10
319 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

744 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

13 Experts available now in Live!

Get 1:1 Help Now