Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

multiple csv to distinct tables - Import to sqlserver

Posted on 2014-03-05
10
Medium Priority
?
353 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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 41

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 41

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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

618 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