title: SQL exec runs error after using WITH Statement
body: <p>I just get a problem executing my sql statement, This is the Northwind db.</p>
  
  <pre><code>    declare @PageIndex int
      declare @PageSize int
      declare @PageLowerBound int
      declare @PageUpperBound int
      declare @sql nvarchar(4000)
  
      select @PageIndex = 3
      select @PageSize = 5
  
      SET @PageLowerBound = @PageSize * @PageIndex
      SET @PageUpperBound = @PageLowerBound + @PageSize + 1
      with cts
      as
      (
      SELECT *
      FROM (SELECT ROW_NUMBER() OVER (ORDER BY OrderID) AS ROW,* FROM Orders)
      AS Orders  WHERE ROW &gt;=@PageLowerBound AND Row&lt;=@PageUpperBound
      )
     select @sql = @sql + 'select * from cte' 
      exec (@sql)
  </code></pre>
  
  <p>(Modified)
  Just modify a little bit, I use select * from cte, I accidently pasted the wrong code. Sorry.
  Actually, i am trying to append a where clause in @sql and execute it, but it throws a error message,saying "Incorrect syntax near the keyword 'exec'."
  What did I do wrong?
  Thank you</p>