SELECT 
 * 
 
FROM 
 `task` 
 
WHERE  
  NOT( ( `name` IS NULL ) OR ( `name` = '' ) ) 
 AND 
 (
		 CASE WHEN :view='year' THEN 
		  YEAR(`start`)=YEAR(:start) 		
	   ELSE 		 
			CASE WHEN :view='month' THEN 
			 ( YEAR(`start`)=YEAR(:start) ) AND ( MONTH(`start`)=MONTH(:start) ) 
		  ELSE 
				CASE WHEN :view='day' THEN 
				 ( YEAR(`start`)=YEAR(:start) ) AND ( MONTH(`start`)=MONTH(:start) ) AND ( DAY(`start`)=DAY(:start) ) 
				ELSE 
				 NULL 
				END 
			END
		 END	 
	)
 AND
  IF( :parent > 0, `parent` = :parent, `parent` IS NULL ) 
 	
ORDER BY
 `start` ASC
 
LIMIT 
 :limit 
 
OFFSET 
 :offset 
 
 
/*

WHERE  
  NOT( ( `name` IS NULL ) OR ( `name` = '' ) ) 
 AND 
 (
		IF( :view='year', YEAR(`start`)=YEAR(:start), NULL )
		
	   OR 
		 
		IF( :view='month', ( YEAR(`start`)=YEAR(:start) ) AND ( MONTH(`start`)=MONTH(:start) ), NULL )
	)
 AND
  `start` < :stop 
 AND
  IF( :parent > 0, `parent` = :parent, `parent` IS NULL ) 
	
*/ 
 
