JohnEfford
Programmer
I have two linked servers that I want to access. Currently the way I am doing this to build the command as shown...
then
this is ok for selections but really long winded for updates and insertions as the products table has lots of feilds.
The following would be a far easier method
This gives the error message
Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near '@Server'.
I have tried declaring the @Server variable as Varchar and NVarchar. Does any one know how to achieve this.
Code:
If @Department = 'P'
Set @Server = N'Pervasive_1'
Else
Set @Sever= N'Pervasive_2'
Set @SqlCommand = N'Select * OpenQuery(' + @Server + N',''Select * from Products'')' ....
Code:
Exec sp_executesql @SqlCommand
this is ok for selections but really long winded for updates and insertions as the products table has lots of feilds.
The following would be a far easier method
Code:
If @Department = 'P'
Set @Server = N'Pervasive_1'
Else
Set @Sever= N'Pervasive_2'
Select * openquery(@Server,'Select * from products') .....
This gives the error message
Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near '@Server'.
I have tried declaring the @Server variable as Varchar and NVarchar. Does any one know how to achieve this.