title: Declaring the scalar variable?
body: <p>I am trying to produce a sql query based report that will allow a date range to be inserted in order to get a selection of the data available.</p>
  
  <p>The problem I am having is that when I try this I get the error:</p>
  
  <blockquote>
    <p>Must declare the scalar variable "@DateFrom".</p>
  </blockquote>
  
  <p>the sql i am using is below:</p>
  
  <pre><code>SELECT
    [Cost Category ID]
  FROM 
     SRVS.dbo.PACostCategories
  WHERE
      (@DateFrom IS NULL OR alias.myDate&gt;= @DateFrom) AND
      (@DateTo IS NULL OR alias.MyDate &lt; DATEADD(d, 1, @DateTo))
  </code></pre>
  
  <p>Any pointers to get me in the right direction much appreciated.</p>