title: Calling parameterized stored procedure in OpenQuery - SQL Server 2008
body: <p>I am calling a stored procedure in <code>OpenQuery</code> and passing parameters to the stored procedure.</p>
  
  <pre><code>declare @Src nvarchar(max),@Tgt nvarchar(max)
  declare @sql_str nvarchar (4000)
  set @Src = '$\VMT\Versions\0900\AMS\'
  set @Tgt = '$\VMT\Versions\0900\Base\'
  set @sql_str = 'exec [Tfs_VMT Collection].dbo.MergeCandidate ''' + @Src+ ''' , ''' +@Tgt+''' ' 
  set @sql_str = 'select * into #test from openquery(ODSSERVER,''' +Replace(@sql_str,'''', '''''') +''')'
  
  print @sql_str
  
  EXEC (@sql_str)
  </code></pre>
  
  <p>but this fails with following error</p>
  
  <blockquote>
    <p>Msg 7357, Level 16, State 2, Line 1<br>
    Cannot process the object "exec [Tfs_VMT
    Collection].dbo.MergeCandidate '$\VMT\Versions\0900\AMS\' ,
    '$\VMT\Versions\0900\Base\' ". The OLE DB provider "SQLNCLI10" for
    linked server "ODSSERVER" indicates that either the object has no
    columns or the current user does not have permissions on that object.</p>
  </blockquote>
  
  <p>I have checked this has nothing to do with permissions.</p>
  
  <p>Can you please help?</p>