How to use variable in target database name for insert statement?

后端 未结 3 738
予麋鹿
予麋鹿 2021-01-23 11:09

I want to declare a server name and use this name in an insert statement. So far all i got is an error message.

declare @machine nvarchar(6);
declare @bar nvarch         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 11:25

    If you need to insert into different databases from the same source database, use dynamic SQL just as others say.

    However, if the problem is that you want to syncronize devserver1 with devserver2, and prodserver1 with prodserver2, and have the other database as a config option, then use synonyms.

提交回复
热议问题