on 06-25-2016 1:01 PM
Is it possible to create template tables within a while loop?
I have a need to create staging tables for all customers of a particular Accounting group type. I'm not sure how the naming of the template tables would be set dynamically?
Any assistance and direction is greatly appreciated.
Thank you!
Hi Jamie,
I guess we can implement this. But you need to have target tables created in DB with your desired name.
Take a script at the end after the dataflow in the while loop and write sql() function to insert data from temp table created to your Target table.
And write if condition based on the while loop condition you defined.
If suppose you while condition is like this ($G_WHL_COND<=4) and you declared this variable as 1 initially and the value of this will be incremented for every loop.
Now write end script like this for the 1st loop
if($G_WHL_COND=1)
begin
sql('Data_store_name','select * into <tablename> from <temp_table>);
end
for the 2nd loop
if($G_WHL_COND=2)
begin
begin
sql('Data_store_name','select * into <tablename> from <temp_table>);
end
If you want to create 4 tables write if conditions 4 times and for each if condition "From table will be your temp table created in DF" and "into table should be your expected target table name"
Make sure you increment $G_WHL_COND in this script after all the if conditions.
Thanks,
Ravi kiran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dirk,
DB wont allow duplicate table right. Like if i run this job today and say my target temp table is <Table_1>
i will write the end script or post load command to rename this table to <table_account> and this will create a table with name <table_account>
and i will run this job again tomorrow and it will try to rename this temp table <table_1> with the name <table_account> which is already present in the DB.. It will throw error..
So what would be the best solution for this... droping <table_account> before the DF starts and rename this <table_1> after the DF completes?
Thanks,
Ravi kiran.
Thanks for the reply Dirk.
But here the requirement is like this
------------------
Is it possible to create template tables within a while loop?
I have a need to create staging tables for all customers of a particular Accounting group type. I'm not sure how the naming of the template tables would be set dynamically?
-------------------------
So which would be best solution..?
Taking a case transform and filtering particular groups and taking temp tables for each output produced from case?
Thank you Dirk and Ravi!
The end result that I'm looking for is to dynamically overwrite the table data on a daily basis for each $Group Table, This tables will be used for base tables within Information Steward so one view can be shared.
So Ravi's solution will override all data in the existing table without a delete statement correct?
Thanks Dirk,
One more question and hopefully the last..
When you say "data flow to write into template table". Do you have a visual example of what this looks like in DS? I'm currently scripting this whole thing and if there is a better way to do this it might make more sense for me to see an example...
This is what I have been thinking off all the time (you really got me confused 😞
In Init you set your counter to 0. The While-loop contains:
Before the data flow you set $Plant_nbr. The data flow loads the template table, using $Plant_nbr as a filter.
After the data flow you drop and rename tables and increment the counter.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.