title: SQL Server : Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '='
body: <p>I'm writing a stored procedure and I'm passing the table names as parameters, but I'm having an error in this part:</p>
  
  <pre><code>DECLARE 
  @TableA nvarchar(255)='TableA',
  @DOCID1 nvarchar(MAX),
  @DOCID2 int;
  
  EXEC ('
  SELECT TOP (1) '+ @DOCID1 +'=DOCID1,'+ @DOCID2 +'=DOCID2
  FROM [' + @TABLEA + ']
  ORDER BY DOCID2')
  </code></pre>
  
  <p>After I run this query I get this error: </p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 2<br>
    Incorrect syntax near '='</p>
  </blockquote>
  
  <p>I have tried and I can't pinpoint the error, at this point I need some help..</p>