SQL query with case datepart -
i data exclude weekends result based on bind variable value. somehow not able query run.
select * tablename a.date >= '2015-04-13' , a.date <= '2015-04-21' , case when :1 = 'y' ((datepart(dw, a.date) + @@datefirst) % 7) not in (0, 1) end
i getting following error : incorrect syntax near keyword 'not'.
use case
expression here over-complicates things, imho. have 2 situations:
- if bind variables
y
, need exclude weekends. - if isn't, want include them.
this logic can achieved simpler (again, imho) usage of or
logical operator:
select * tablename a.date >= '2015-04-13' , a.date <= '2015-04-21' , (:1 != 'y' or ((datepart(dw, a.date) + @@datefirst) % 7) not in (0, 1))
Comments
Post a Comment