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

Trying to pull from many tables with similar names using one for each loop container Expand / Collapse
Author
Message
Posted Thursday, November 01, 2012 3:05 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, April 10, 2014 6:20 PM
Points: 220, Visits: 695
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
Post #1380048
Posted Friday, November 09, 2012 9:03 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 9:25 AM
Points: 7,070, Visits: 12,523
Do all the tables have the same schema?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1383322
Posted Monday, November 12, 2012 2:03 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, April 10, 2014 6:20 PM
Points: 220, Visits: 695
Hi and thank you for the reply. Yes they all have the same schema.
Post #1383866
Posted Monday, November 12, 2012 2:28 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:16 PM
Points: 5,986, Visits: 6,931
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
Post #1383880
Posted Tuesday, November 13, 2012 10:45 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, April 10, 2014 6:20 PM
Points: 220, Visits: 695
Thanks for the reply Craig. I'll play around with that and report back.
Post #1384200
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse