• You can't have dynamic code in the view. But you can write dynamic script (or procedure) that will generate DROP and CREATE VIEW statements (or ALTER VEW) with all your current tables and then execute it. You can then schedule this script as a job an run it every day after new table is created.

    After a year it's going to look kinda ugly. I wonder if there is a limit on a number of UNIONs in a query?

    Or are you going to drop those archive tables periodically? Why not simply have one history table with a date stamp and keep adding to it?

    --Vadim R.