smackababy
Lifer
Is there a way to run a select statement to get a set of table names and then query using those results in a statement?
This might sound a bit confusing. So, I have a database set up to accommodate hundreds of millions of files and it creates it's own tables at a certain point (when a table gets greater than 10 million rows, it creates a new table). Currently, we have around 5640 tables and we need to check basically each table (there are a few system tables and such, so we can skip those). I can easily generate a list of table names, but I really don't want to run 5640 individual selects.
Is there some way to use those results as the table?
I've attempted to do this using a temp table, but unfortunately, my SQL is weak. And I don't know if there is some kind of equivalent of tsql type of thing on DB2. Maybe using FINAL TABLE?
What I have so far:
That returns the table names, I just want to use that as the from and query based on something within each.
Thanks,
This might sound a bit confusing. So, I have a database set up to accommodate hundreds of millions of files and it creates it's own tables at a certain point (when a table gets greater than 10 million rows, it creates a new table). Currently, we have around 5640 tables and we need to check basically each table (there are a few system tables and such, so we can skip those). I can easily generate a list of table names, but I really don't want to run 5640 individual selects.
Is there some way to use those results as the table?
I've attempted to do this using a temp table, but unfortunately, my SQL is weak. And I don't know if there is some kind of equivalent of tsql type of thing on DB2. Maybe using FINAL TABLE?
What I have so far:
Code:
select distinct arsseg.table_name from sa2 inner join arsag
on sa2.load_agid = arsag.agid
inner join arsseg
on arsseg.agid = arsag.agid
That returns the table names, I just want to use that as the from and query based on something within each.
Thanks,