I have an environment where our live database, (MC_Live), gets backed up and restored to a development environment, (MC_Training), periodically. In this database, there are some stored procedures that update a second database via a linked server connection. When working in MC_Live, we want to update a 'Live' linked database, (MobileFrame). When connected to MC_Training, we need to hit the 'development' linked database (MobileDev) on a second server.
Ok, that said, I have a Merge statement something like this:
Now for the $64k question. The 'LiveData' above is on a different server from the 'DevData' that needs to be updated. Which would be a better approach to change database/table references based on the database where the procedure resides:
1) Use a full IF db_name() = 'LiveData' Begin ... End IF db_Name() = 'MC_Training BEGIN .... END
2) Use dynamic SQL to change the [Server].[Database].[Schema].
references based on the Database we're attached to.
Opinions anyone?
Much thanks in advance,
Paul
Ok, that said, I have a Merge statement something like this:
Code:
Merge [MobileData].[dbo].[SomeTable]
Using (SELECT col1, col2
FROM [MC_Live].[dbo].[AnotherTable]
WHERE ...)
:
:
Now for the $64k question. The 'LiveData' above is on a different server from the 'DevData' that needs to be updated. Which would be a better approach to change database/table references based on the database where the procedure resides:
1) Use a full IF db_name() = 'LiveData' Begin ... End IF db_Name() = 'MC_Training BEGIN .... END
2) Use dynamic SQL to change the [Server].[Database].[Schema].
Opinions anyone?
Much thanks in advance,
Paul