Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

SSIS dynamic mapping of columns Expand / Collapse
Author
Message
Posted Thursday, January 1, 2009 6:36 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 4, 2014 7:44 AM
Points: 115, Visits: 646
Can any body let me know how to map the columns dynamically in ssis ....
Suppose I have some 10 tables in a database.. I need to export the data in these tables to tables in oracle database.

I need to migrate data from sql to oracle. Since the method is same for all tables I think we can make it dynamic so that for each table it should migrate the data.

I searched throughout the net but I could not able to find a method for this. Can anybody let me know how we can achieve this dynamically.

Table schema in sql and oracle are same. How can I do this?
Post #628424
Posted Friday, January 2, 2009 4:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:49 AM
Points: 20, Visits: 145
We had a similar problem, although it was using text files and other ODBC connections as the source. I also looked through the web, and unfortunately as far as i know, the answer is you can't do it in a Data Flow Task.

If however, you try using a Bulk Insert Task, or using an execute SQL task, you can certainly make those dynamic (you can use expressions to change the connection strings, etc). If you need more help on how to do this, let me know.
Post #628687
Posted Friday, January 2, 2009 5:49 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 4, 2014 7:44 AM
Points: 115, Visits: 646
We had a similar problem, although it was using text files and other ODBC connections as the source. I also looked through the web, and unfortunately as far as i know, the answer is you can't do it in a Data Flow Task.

If however, you try using a Bulk Insert Task, or using an execute SQL task, you can certainly make those dynamic (you can use expressions to change the connection strings, etc). If you need more help on how to do this, let me know.


Can you please post the solution which u feel its working... If it is feasible I will use that method only.
Post #628736
Posted Monday, January 5, 2009 5:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:49 AM
Points: 20, Visits: 145
Hi

You won't be able to use the Bulk Insert Task because that only applies to files and not database connections. So if you want to use the Execute SQL task, you can do the following (this may not be the ideal way of doing it, but it works):

SUMMARY:
Read in the list of tables to variables -> Use a ForEach Loop container to read through each of these and amend an Execute SQL task on each loop -> Make the Execute SQL task do a simple TSQL insert.

DETAILS:
1. Set up a Linked Server (Server Objects > Linked Servers) to the source DB (if you can't use one of SQL Server's built-in providers then you can set up an ODBC connection and then connect to that).

2. In SSIS create a variable of type Object

3. Create a task that reads in the list of tables you need and maps to the variable. For example, you could have a database table that contains two columns such as SourceTable and DestinationTable. In that case use an Execute SQL task to do a simple select on that table, but make sure you then map that Result Set to the object variable.

4. Create variables to hold each value. So in the example above, create one variable to hold the SourceTable name and one to hold the destination one.

4. Create a ForEach Loop container. Edit the container and on the Collection section ensure the Enumerator is set to ForEach ADO Enumerator and you select the Object variable in the section below. Then go to the Variable Mappings and map each output from your select statement earlier to your variables. So for example, if your select statement in step 3 outputs 2 columns, then in the mappings section under variables select your SourceTable variable and under Index enter 0, and similarly select you DestinationTable variable and Index 1. So now your variables will contain the table names you need on each loop.

5. Place an Execute SQL task inside the container. Edit the task and on the Expressions section, add an Expression for SqlStatementSource. Then give it a value of something like:

"INSERT INTO " + @[User::DestinationTable] + " SELECT * FROM OPENQUERY(XXXXXXX, 'SELECT * FROM " + @[User::SourceTable] + "')"

Here the XXXXX will be the name of the Linked Server you set up at the start. Of course, you can test the statement first in a normal SQL Query window to make sure it works first:

INSERT INTO AAAAAAA
SELECT * FROM OPENQUERY(XXXXXX, 'SELECT * FROM BBBBBB')

where AAAAA is your destination table and BBBBB is your source table.

One final note - if you can read directly from the source DB from SQL Server (e.g. if it is just another SQL Server DB), then you don't need to do step 1, and in the final step your SQL query will be even simpler, i.e. of the form:

INSERT INTO AAAAA
SELECT * FROM BBBBBB

Hope that helps. Give me a shout if you still get stuck
Post #629717
Posted Monday, January 5, 2009 6:47 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 4, 2014 7:44 AM
Points: 115, Visits: 646
Thanks Naveed...

I will try this.
Post #629756
Posted Thursday, January 22, 2009 8:31 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 24, 2012 10:19 AM
Points: 2, Visits: 17
Hi.
I was reading your article and it is very interesting. Can you send me a graphic example?
Thank you for your time
Post #641766
Posted Thursday, January 29, 2009 4:57 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:49 AM
Points: 20, Visits: 145
I have attached some images that may help.

  Post Attachments 
1. variables.JPG (1,367 views, 34.07 KB)
2. sql before felc.JPG (1,188 views, 10.66 KB)
3. get the reference data.JPG (1,138 views, 52.42 KB)
4. felc collection.JPG (997 views, 48.27 KB)
5. felc variable mappings.JPG (1,087 views, 34.53 KB)
6. sql inside felc.JPG (1,020 views, 65.61 KB)
Post #645745
Posted Thursday, January 29, 2009 11:52 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 4, 2014 7:44 AM
Points: 115, Visits: 646
Thanks naveed.

Really it is helpful.
Post #646255
Posted Thursday, January 29, 2009 3:01 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 24, 2012 10:19 AM
Points: 2, Visits: 17
The images are good... can I use this in sqlserver 2000?

thank you very much by your help

AMTZVA
Post #646451
Posted Thursday, January 29, 2009 4:06 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:49 AM
Points: 20, Visits: 145
Amtzva

This is all specific to SSIS which didn't appear until SQL Server 2005. In SQL Server 2000 you can use DTS and make things dynamic too, but requires a completely different method.
Post #646508
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse