title: SQL Stored-Proc using parameter for server name?
body: <p>I have a stored procedure that gets all the non-system database names from a SQL Server:</p>
  
  <pre><code>select name from MySQLServer.master.sys.databases
  where name not like ('master')
  and name not like ('tempdb')
  and name not like ('msdb')
  and name not like ('model')
  and name not like ('Admin')
  </code></pre>
  
  <p>What I would like to do is pass the server name as a parameter, so this sproc is more reusable:</p>
  
  <pre><code>@servername = 'some passed servername'
  
  select name from @servername.master.sys.databases
  where name not like ('master')
  and name not like ('tempdb')
  and name not like ('msdb')
  and name not like ('model')
  and name not like ('Admin')
  </code></pre>
  
  <p>Can this be done?  How would I do this?</p>
  
  <p>Could I create a variable like:</p>
  
  <pre><code>DECLARE @serverPointer nvarchar(MAX)
  SET @serverPointer = @servername + '.master.sys.databases'
  
  select name from @serverPointer
  </code></pre>
  
  <p>Any help would be appreciated.</p>