I'm fairly new to SQL so perhaps I am missing something but what I am trying to do is have a script I wrote select a certain database depending on @@ServerName. This script will be run by the testing department and needs to work regardless of connection.
IF @@SERVERNAME IN ('X')
USE DataBaseA
ELSE IF @@SERVERNAME IN ('Y')
USE DataBaseB
ELSE
USE DataBaseC
What happens is DataBaseB does not exist on server X so I receive the error of "no database exists". As well, DataBaseC lacks certain columns in tables that DataBaseA has (DataBaseC will later get these columns but are not there right now). Is there a different way to force the code to properly use the right database and not throw errors?