(CASE

 WHEN t.TASKTYPE='TASK'        THEN IFNULL((select SUM(STUNDEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT BETWEEN 1 and {{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 BETWEEN 1 and {{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 BETWEEN 1 and {{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 BETWEEN 1 and {{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 BETWEEN 1 and {{monat}} and d.PSP like CONCAT(t.PSPCODE,'.%')),0)

        ELSE 0

        END) as 'ISTPHKUM',

       (CASE

        WHEN t.TASKTYPE='TASK'        THEN IFNULL((select SUM(KOSTEN) from CCILV d where d.JAHR={{jahr}} and d.MONAT BETWEEN 1 and {{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 BETWEEN 1 and {{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 BETWEEN 1 and {{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 BETWEEN 1 and {{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 BETWEEN 1 and {{monat}} and d.PSP like CONCAT(t.PSPCODE,'.%')),0)

        ELSE 0

        END) as 'ISTKOSTKUM',

       t.TASKATTRIB as 'FCPH0112',

       'NO_DATA' as 'FCKOST0112'

  from CCTASK t

 where t.PROJECT='{{project}}'