Home Forums SQL Server 2005 T-SQL (SS2K5) Using a variable for a linked server name in stored procedures RE: Using a variable for a linked server name in stored procedures

  • I haven't used OPENQUERY a lot in my time but this should work. Use a generic name for your linked server, e.g. ERPSERVER and then, after creating it in all of your environments use sp_setnetname to set the network name of the the target. So in live you would run sp_setnetname 'ERPSERVER','ERPLIVE', in test you would run sp_setnetname 'ERPSERVER','ERPTEST' etc.

    Using the generic name means your code is applicable in any of your environments so you don't have to re-create anything after a database restore.

    Running sp_setnetname alters the column srvnetname in master.dbo.sysservers.

    Hope that helps,

    Mike