title: Using Parameters in DATEADD function of a Query
body: <p>I am trying to us the <a href="http://technet.microsoft.com/en-us/library/ms186819.aspx" rel="noreferrer">DateAdd</a> function of SQL in my Query. The problem is when I use a parameter to set the second arguement, the <em>number</em> argument I get an error which will say something like this:</p>
  
  <blockquote>
    <p>Failed to convert parameter value from
    a Decimal to a DateTime</p>
  </blockquote>
  
  <p>While if I enter it parameterless, i.e hardcode an Int, it works fine.</p>
  
  <p>This works:</p>
  
  <pre><code>SELECT     FieldOne, DateField
  FROM         Table
  WHERE     (DateField&gt; DATEADD(day, -10, GETDATE()))
  </code></pre>
  
  <p>while this does not:</p>
  
  <pre><code>SELECT     FieldOne, DateField
  FROM         Table
  WHERE     (DateField&gt; DATEADD(day, @days, GETDATE()))
  </code></pre>
  
  <p>Where @days = -10</p>
  
  <p>Any ideas into what I am doing wrong? Incidentally I am setting this variable in SQL Server Manager, as I am trying to work out a bug in my DataAccess code. Not sure if that makes a difference. </p>
  
  <p>Thanks</p>