datetime - "dynamic" where statement in sql server 2008 r2 -


i need pass 2 different where statements based on result in select statement. base query following

select table1.taskid,      table1.starttime,      table1.endtime,      table1.everyminutes,      table3.dlid,      table3.run  table1 join table2     on table1.taskid = table2.taskid left join table3     on table1.taskid = table3.taskid table2.active = '1' order taskid asc 

what struggling if table3.run = '1', need include following

convert(date,getdate()) in (select dldate table4 dlid = table3.dlid) 

if table3.run = '0' need have following

convert(date,getdate()) not in (select dldate table4 dlid = table3.dlid) 

and finally, if table3.run = 'null' need have neither of statements

try

select table1.taskid,      table1.starttime,      table1.endtime,      table1.everyminutes,      table3.dlid,      table3.run  table1 join table2      on table1.taskid = table2.taskid left join table3     on table1.taskid = table3.taskid table2.active = '1'     , (             (table3.run = '1'               , convert(date,getdate())               in (select dldate table4 dlid = table3.dlid))            or (table3.run = '0'               , convert(date,getdate()) not in              (select dldate table4 dlid = table3.dlid))           or table3.run = 'null'   -- incredibly bad idea          ) order taskid asc 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -