title: CASE statement in where clause in tsql query
body: <p>I'm trying to write a case statement in the where clause for a query I am working on. I am importing the code in Crystal reports and I am basically trying to say if the variable 'type' is set to 'create' run for this date range in the where clause else run for a different date range. It keeps giving me an error. I can't seem to identify what is wrong with my syntax here. Help anyone?</p>
  
  <pre><code>DECLARE @Date1 DATETIME
  DECLARE @Date2 DATETIME
  DECLARE @type VARCHAR(20)
  SET @Date1 = '2010-1-1'
  SET @Date2 = '2010-2-1'
  SET @type = '{?DateType}'
  
  select *
  from filled
  WHERE   
      (CASE WHEN @type = 'create' THEN 
      filled.CREATEDON &gt;= @Date1
      AND filled.CREATEDON &lt; DATEADD(d, +1, @Date2)
      WHEN @type &lt;&gt; 'create' THEN   
      filled.datefilled &gt;= @Date1
       AND filled.datefilled &lt; DATEADD(d, +1, @Date2) 
       END)
  </code></pre>