Possible Duplicate:
How to use variable for database name in t-sql
If I do Select * from Production.dbo.MatchTable it works.(where Production is database name)
Now I need to use it in a variable first as
Declare @dbName As varchar(20) = 'Test'
And then if I do Select * from @dbName.dbo.MatchTable I get an error
Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '.'.
Then how can I use it.
The reason is that, at the time of testing we will change the db name. So changing the same in many places in many store procs will be an issue.
Also I cannot write a dynamic query.
So what may be the way of doing it? Synonyms won't work as it is not applicable for database name.
Thanks