title: Passing parameter as a string into dynamic SQL
body: <p>Considering this SQL statement:</p>
  
  <pre><code>DECLARE @SQLString          NVARCHAR(MAX)
  
  SET @SQLString = '
  DECLARE @CountryCode    varchar(3)
  DECLARE @CountryName    varchar(60)
  
  DECLARE AutoCursor CURSOR FOR
  
      SELECT DISTINCT 
          CountryCode, 
          CountryName 
      FROM Country
  
  OPEN AutoCursor
  FETCH FROM AutoCursor INTO @CountryCode, @CountryName
  
      WHILE @@fetch_status = 0
      BEGIN
              BEGIN TRAN
  
                  EXEC SP_StoredProcedure_1
                      @ExtraWhereClause   = N'' AND CountryCode= ''''@CountryCode'''' '',
                      @Name               = @CountryName
  
              COMMIT TRAN                             
      FETCH Next FROM AutoCursor INTO @D_Nationcode, @C_Name
      END
  CLOSE AutoCursor
  DEALLOCATE AutoCursor;  
  '
  PRINT (@SQLString)
  EXEC (@SQLString)
  </code></pre>
  
  <p>How can I pass <code>@CountryCode</code> as a parameter in a string?</p>
  
  <p><code>@ExtraWhereClause = N'' AND CountryCode= ''' + @CountryCode + ''' ''</code>, doesn't seem to work as <code>@CountryCode</code> is already used in dynamic SQL.</p>