SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Trying to pull from many tables with similar names using one for each loop container


Trying to pull from many tables with similar names using one for each loop container

Author
Message
MMartin1
MMartin1
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7457 Visits: 2033
Hi. I have a situation where I have various tables named like, for example,

mytable_t1, mytable_t2, ... and so on.

I'd like to copy these tables nightly to another database using SSIS. Since the amount of tables can increase I am wondering if there is a way to do so dynamically so that the program is aware of when another table gets added.

So far I have>
created a t-sql task that gets the tables along with a row id inserted into a object type ssis variable. I connect this variable to a forEach loop container using the ADO enumerator and the variable as the source object. I want to map the second column (table name) to another variable (user::currentTable). I thus map this second variable to index 1 to get the second column in the container's variable mapping dialogue. I hope this is correct.

Inside the container is a data flow with a source and destination only.
I am curious if anyone has encountered this situation and how the dataflow needs to be configured.

Thanks

----------------------------------------------------
How to post forum questions to get the best help
Orlando Colamatteo
Orlando Colamatteo
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41762 Visits: 14413
Do all the tables have the same schema?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
MMartin1
MMartin1
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7457 Visits: 2033
Hi and thank you for the reply. Yes they all have the same schema.

----------------------------------------------------
How to post forum questions to get the best help
Evil Kraig F
Evil Kraig F
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21683 Visits: 7660
mmartin1 (11/1/2012)

I'd like to copy these tables nightly to another database using SSIS. Since the amount of tables can increase I am wondering if there is a way to do so dynamically so that the program is aware of when another table gets added.


I would approach this slightly differently.

First, pull the tablelist into a package object for Recordsets with something similar to the following:
SELECT [name] FROM sys.sysobjects WHERE [name] like 'mytable_%'

Next, fire up the forEach loop like you've done, feeding said result into another string package variable. Now, for the internals of the loop:

Quick script to feed a full SELECT * FROM <packagevariable> statement (full query) into yet another string package variable. This will be fed into the dataflow for the OLEDB source as an expression for the SQL statement. You can adjust the target table in a similar way via expressions and the original table's name.


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
MMartin1
MMartin1
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7457 Visits: 2033
Thanks for the reply Craig. I'll play around with that and report back.

----------------------------------------------------
How to post forum questions to get the best help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search