?
Solved

multiple csv to distinct tables - Import to sqlserver

Posted on 2014-03-05
10
Medium Priority
?
346 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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
Suggested Courses

765 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