title: Using local variable inside dynamic SQL does not work
body: <p>This static query using a parameter returns one row:</p>
  
  <pre><code>DECLARE @sqltext nvarchar(max)
  DECLARE @status varchar(100)
  SET @status = 'Active: Complete'
  
  select * from status where StatusTitle = @status and type_id = 800
  </code></pre>
  
  <hr>
  
  <p>However, using the parameter in a dynamic SQL query as follows does not return any rows at all:</p>
  
  <pre><code>SET @sqltext = 'SELECT s.StatusID
  FROM   [Status] s
  WHERE  (
  ( s.StatusTitle ='' + @status + '' )
  AND s.[type_id] = 800  )'
  
  EXECUTE sp_executesql @sqltext
  </code></pre>
  
  <p>I know there is something wrong with the WHERE clause. I can't figure out how to correct it.</p>