I have a system that fetches its data from different databases on the same server. These databases are newly attached to the server annually, e.g. at the at the beginning of 2013, a database called 2012 is attached.
I want to create a stored procedure that fetches the user’s input which can be anything from 2005 (year). Based on the year the user enters, the stored procedure should go to that database (whose name will be the year the user entered) and search for the data (with its parameter being the year the user entered) inside the database which will also has a table with the same name as the database (i.e the table will have the same name as the year name).
Hope this makes sense
It would be a good idea to parametrize the query.
e.g.
Check out this