select t1.id,t1.name,t2.status,t2.project,t2.id as taskID, if($status='','', t1.status) as projectstatus, (case when t2.deadline < CURDATE() and t2.deadline != '0000-00-00' and t2.status != 'closed' and t2.status != 'done' and t2.status != 'cancel' then 1 else 0 end) as timeout from TABLE_PROJECT as t1 left join TABLE_TASK as t2 on t1.id=t2.project where t1.deleted='0' and t2.deleted='0' and if($beginDate='', 1, t1.begin>=$beginDate) and if($endDate='',1,t1.end<=$endDate) having projectstatus=$status