I have several link server on my server (about 20 servers). on these server exists a similar database and I want to execute a stored procedure on these server in depend of a parameter on my stored procedure on my server. I have following query for this idea.
Create procedure test
(
@ServerName VarChar(100),
@Code int
)
As
IF(@ServerName = 'Server1')Begin
Exec Server1.SGDB.dbo.DocInsert @Code
End Else IF(@ServerName = 'Server2')Begin
Exec Server2.SGDB.dbo.DocInsert @Code
End Else IF(@ServerName = 'Server3')Begin
Exec Server3.SGDB.dbo.DocInsert @Code
.
.
.
End Else IF(@ServerName = 'Server20')Begin
Exec Server20.SGDB.dbo.DocInsert @Code
End
End
Can I have a dynamic query with @ServerName
parameter without using exec(string command).
thanks in advance.