title: How to use datetime value in an SSIS expression builder to formulate SQL command?
body: <p>I am trying to use Ado.Net Sql command to select data from a table with a date filter.</p>
  <pre><code>SELECT  COLUMN1
      ,   COLUMN2 
  FROM    TABLENAME 
  WHERE   DATE_INSERTED &gt; @[User::LastInsertDate]
  </code></pre>
  <p>Both <code>Date_Inserted</code> and <code>@[User::LastInsertedDate]</code> are of type <code>DateTime</code>. When I try to evaluate expression in the expression builder l get the following error;</p>
  <blockquote>
  <p>The expression might contain an invalid token, an incomplete token, or
  an invalid elemnt, it might not be well-formed, or might be missing
  part of a required element such as a parenthesis.</p>
  </blockquote>
  <p>Problem diagnosis from original revision of accepted answer:</p>
  <blockquote>
  <p>Here is my understanding of your question. I believe that you created
  two variables under package scope. A variable named <code>LastInsertDate</code>
  of <em>DateTime</em> data type and another variable named <code>SqlQuery</code> of
  <em>String</em> data type to store the SQL SELECT command.</p>
  <p><img src="https://i.stack.imgur.com/9ufp0.png" alt="Variables declaration" /></p>
  <p>You set the <em>EvaluateAsExpression</em> property on variable <code>SqlQuery</code> to
  <strong><code>True</code></strong>. You then entered the following command <code>SELECT COLUMN1, COLUMN2 FROM TABLENAME WHERE DATE_INSERTED &gt; @[User::LastInsertDate]</code></p>
  <p><img src="https://i.stack.imgur.com/ctslX.png" alt="Expression Builder" /></p>
  <p>When you clicked <em>EvaluateAsExpression</em>, you got the following error
  message:</p>
  <pre><code>Expression cannot be evaluated. Additional information: Attempt to
  parse the expression &quot;SELECT COLUMN1, COLUMN2 FROM TABLENAME WHERE
  DATE_INSERTED &gt; @[User:LastInsertDate]&quot; failed. The expression might
  contain an invalid token, an incomplete token, or an invalid element.
  It might not be well-formed, or might be missing part of a required
  element such as a parenthesis. 
  </code></pre>
  <p><img src="https://i.stack.imgur.com/kkxO0.png" alt="Error message" /></p>
  </blockquote>