Must declare the scalar variable "@serverName"
<p>I know that we have a lot of answers for this problem but I still don't understand what really the cause of this error.</p>

<p>I've created a stored procedure like this.</p>

<pre><code>CREATE PROCEDURE [dbo].[storedProc_dataPull] 
     @serverName nvarchar(30), 
     @dbName nvarchar (30), 
     @tblName nvarchar(30)
AS BEGIN
    DECLARE @sql nvarchar(500)
    DECLARE @ds nvarchar(500)

    SET @ds = 'Data Source=phmnldb16\eaudit;user id=YYYY;password=XXXX'
    SET @sql = 'SELECT @serverName, @dbName, sdb1.* from
               OPENDATASOURCE(''SQLOLEDB'', '+Char(39)+ @ds +Char(39)+ ').AUDIT_FSA_170_001.AUD170.Workflow sdb1)'
    INSERT INTO sampleDatabase.dbo.WorkFlowCopy
      ([ServerName]
      ,[DBName]
      ,[ID]
      ,[ActivityDefinitionID]
      ,[ParentID]
      ,[Caption]
      ,[Description]
      ,[ShortDescription] 
      ,[Name]
      ,[Order]
      ,[ReferenceNumber]
      ,[ShowOnNavigation]
      ,[Status]
      ,[InUseBy])

    EXEC (@sql)
</code></pre>

<p>And when I tried to execute it..</p>

<pre><code>EXEC storedProc_dataPull 'serverName', 'dbName', 'tblName'
</code></pre>

<p>I always got this error: </p>

<blockquote>
  <p>Msg 137, Level 15, State 2, Line 1<br>
  Must declare the scalar variable "serverName"</p>
</blockquote>