SQL Server: Using 4 part identifiers when database may be on the same server
Use a synonym, and just don't sync the synonyms. So when it is on a local server:

CREATE SYNONYM dbo.FooBar FOR DBName.dbo.TableName;


When it is remote:

CREATE SYNONYM dbo.FooBar FOR ServerName.DBName.dbo.TableName;


Now all your code just has to reference dbo.FooBar no matter where it is.