Search code examples
sqlsql-serverreporting-servicesssrs-2008ssrs-2012

SQL query to omit certain dates for ssrs


Hi I have a query that works where my where clause omits the date 1/1/2017 and 3/1/2017. However I want to use this query for an SSRS report so it would just be a @begdate and @enddate instead of these hard coded fields. Is there a way to omit these 2 dates only?

      where 
 ((Scheduled_Time >= '01/01/2014 00:00:00' and Scheduled_Time <= '12/31/2016 23:59:59' ) --filter  out 1/1/2017
  or  (Scheduled_Time >= '01/02/2017 00:00:00'  and Scheduled_Time <= '02/28/2017 23:59:59') --filter out 3/1/2017
  or  (Scheduled_Time >= '03/2/2017 00:00:00'  and Scheduled_Time <=  '06/30/2017 23:59:59') )

Solution

  • Just remove those dates, and then use your parameters...

    where cast(Scheduled_Time as date) <> '20170101' 
          and cast(Scheduled_Time as date) <> '20170301'
          and Scheduled_Time >= @begdate
          and Scheduled_Time <= @enddate