I am trying to figure out of there is any way that the below can work at all? Basically, it will be used in a Stored Procedure withthe DatabaseName passed in as a parameter. I have 3 databases with the same structure and tables and I need to choose which one to select from. Obviously i could have 3 sections of code so....
If @DatabaseName = 'FirstDatabase'
But I don't want to do that because i'd like it to be dynamic, see the below code............
DECLARE @DatabaseName As varChar(50)
@DatabaseName = 'Test1'
USE @DatabaseName SELECT * FROM TestTable
Any help gratefully received.