title: T-SQL dynamic linked server
body: <p>I have two separated enviroments (Test and Production). Each environment has two servers (istN and istG).</p>
  
  <p><strong>And their linked servers:</strong></p>
  
  <ul>
  <li><p>Test (linked server from istG to istN): test01\istN. 
  If used in a query is:</p>
  
  <p><code> SELECT * FROM [test01\istn].MyDatabase.dbo.Table01 </code></p></li>
  <li><p>Production (linked server from istG to istN) production01\istn
  If used in a query is:</p>
  
  <p><code> SELECT * FROM [production01\istn].MyDatabase.dbo.table01 </code></p></li>
  </ul>
  
  <p>We use a release-system that deploy the same SQL script in each enviroment (test and production) regardless of the environment:</p>
  
  <p>so how is possibile to write only one script that can be used in the enviroments?
  is there a method to get a dynamic linked server?
  like this:</p>
  
  <p><code>   SELECT * FROM [@variable].MyDatabase.dbo.table01 </code></p>
  
  <p>Thanks.</p>