The integration software that my client is using is pulling over ISAM files from a RMS system and creating lots of tables that all have identical schemas, but nonetheless the software they use doesn’t support merging them together.
Here’s some example table names:
- SOME_TABLE_XYZ_2012OCT
- SOME_TABLE_ABC_2012OCT
- SOME_TABLE_LMN_2012OCT
- SOME_TABLE_XYZ_2012NOV
- SOME_TABLE_ABC_2012NOV
- SOME_TABLE_LMN_2012NOV
I need to roll these all up into a single view named SOME_TABLE, with the data union all’d together. It must be dynamic because there can be new 3 char codes and obviously, monthly new tables being created.
Ideally I’d like a SP that creates a view named SOME_TABLE, then I can query off of SOME_TABLE to do the work that I need on it (scheduled ETL into a sql server 2012 data warehouse). I know that I could just have the SP return a cursor, but creating the view gives me flexibility to make it an indexed view if I need for performance, and ease of use from other ETL tools.
I figure on querying sys.tables (or whatever it is), and working from there to build up a sql statement for a create view.
Any other bright ideas on how to approach this?
You can use this query batch to create the view. But you need to keep updating it.
This is a stored proc that takes the base table name, and creates a view for it (I wrapped the above code into a proc that takes a parameter)