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:

  1. if bind variables y, need exclude weekends.
  2. 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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -