(CASE

 WHEN t.TASKTYPE='TASK'        THEN IFNULL((select SUM(STUNDEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP=t.PSPCODE and d.USKURZZ=t.TASKRESP),0)

 WHEN t.TASKTYPE='JAPAP'       THEN IFNULL((select SUM(STUNDEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP=t.PSPCODE),0)

 WHEN t.TASKTYPE='JAPVORHABEN' THEN IFNULL((select SUM(STUNDEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP in 

                                           (select tt.PSPCODE from CCTASK tt where tt.PARENTID=t.TASKID)),0)

 WHEN t.TASKTYPE='JAPBEREICH'  THEN IFNULL((select SUM(STUNDEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP in 

                                           (select tt.PSPCODE from CCTASK tt where tt.PARENTID in (select ttt.TASKID from CCTASK ttt where ttt.PARENTID=t.TASKID))),0)

 WHEN t.TASKTYPE='JAP'         THEN IFNULL((select SUM(STUNDEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP like CONCAT(t.PSPCODE,'.%')),0)

 ELSE 0

 END) as 'ISTPH',

(CASE

 WHEN t.TASKTYPE='TASK'        THEN IFNULL((select SUM(KOSTEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP=t.PSPCODE and d.USKURZZ=t.TASKRESP),0)

 WHEN t.TASKTYPE='JAPAP'       THEN IFNULL((select SUM(KOSTEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP=t.PSPCODE),0)

 WHEN t.TASKTYPE='JAPVORHABEN' THEN IFNULL((select SUM(KOSTEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP in 

                                           (select tt.PSPCODE from CCTASK tt where tt.PARENTID=t.TASKID)),0)

 WHEN t.TASKTYPE='JAPBEREICH'  THEN IFNULL((select SUM(KOSTEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP in 

                                           (select tt.PSPCODE from CCTASK tt where tt.PARENTID in (select ttt.TASKID from CCTASK ttt where ttt.PARENTID=t.TASKID))),0)

 WHEN t.TASKTYPE='JAP'         THEN IFNULL((select SUM(KOSTEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT= and d.PSP like CONCAT(t.PSPCODE,'.%')),0)

 ELSE 0

 END) as 'ISTKOST',