title: Using a variable in Dynamic Query in SQL Server
body: <p>What I'm trying to do from this query is i'm trying to get all the rows which are older than the specified Cutoffnumber from customertransaction table: </p>
  
  <pre><code>@Cutoffnumber INT
  
  SELECT @SQL = 'SELECT * FROM customertransaction WHERE DATEDIFF(DD, Transactiondate, GETDATE()) &gt; @Cutoffnumber '
  </code></pre>
  
  <p>But i'm getting the below error, Note that this is a dynamic SQL query.</p>
  
  <blockquote>
    <blockquote>
      <p>Must declare the scalar variable "@Cutoffnumber"</p>
    </blockquote>
  </blockquote>
  
  <p>How should I go about.</p>