Reputation: 3279
Is it allowed to write queries with dynamic source table? the system that I am developing creates a backup of the current database per week. so the most active database would be mainDB, the previous week backup would be named as mainDb20170327, and the week before that would be mainDb20170320
I need to create a dynamic view that is hosted in each of these database instances. so mainDb has a view named view_mainDb, and mainDb20170320 has a view named view_mainDb20170320.
In the sql query of the view, how can I make the source db instance dynamic?
I tried to user adding the text and concatenating but it doesn't seem to be possible. Or I'm missing something.
Upvotes: 2
Views: 44
Reputation: 562338
The definition of a view must be fixed. You can't make any part of it dynamic.
You'll have to write a stored procedure to do what you want to do, or else do it in application code.
Upvotes: 2