Home Forums SQL Server 2005 T-SQL (SS2K5) Case statement within a where clause - based on 2 variables RE: Case statement within a where clause - based on 2 variables

  • How about this:

    SELECT Customer, [Type], DueDate1, DueDate2 FROM dbo.myTable mt

    WHERE mt.[Type] = @Type

    AND ((@Condition1=1 AND mt.DueDate1 BETWEEN @DueDate1 AND @DueDate2) OR (@Condition1<>1))

    AND ((@Condition2=1 AND mt.DueDate2 BETWEEN @DueDate1 AND @DueDate2) OR (@Condition2<>1))

    ...or am I missing something?