如何讓單條SQL有條件地更改目標服務器?針對不同服務器的條件SQL
所以我的本地開發機器上,我可以運行它,並有命令
INSERT INTO [sds].[dbo].[Team_Email_Addresses]
SELECT [class] AS 'Team number' ,
[description] AS 'Team name' ,
[DutyEmail] AS 'Team email address'
FROM [DEVSERVER].[cases].[dbo].[sp_class]
WHERE [status] = 1
但是在測試機上我想同一塊SQL的運行,並有命令
INSERT INTO [sds].[dbo].[Team_Email_Addresses]
SELECT [class] AS 'Team number' ,
[description] AS 'Team name' ,
[DutyEmail] AS 'Team email address'
FROM [TESTSERVER].[cases].[dbo].[sp_class]
WHERE [status] = 1
我使用一個變量@TGT
並將其設置爲任何devserver
或testserver
與SQL FROM [@TGT].[cases].[dbo].[sp_class]
試過,但我得到一個錯誤Could not find server '@TGT' in sys.servers.
Yeap這些是兩臺服務器的名稱 – SteveC