SHARE
TWEET

Untitled

a guest Sep 30th, 2019 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BEGIN
  2.     FOR accountnames IN (
  3.         SELECT
  4.             UPPER(BRUGERE)
  5.         FROM
  6.             tmp_StatCPRBunker
  7.         ORDER BY
  8.             UPPER(BRUGERE) DESC
  9.             )
  10.            
  11. LOOP
  12. -- Bunke_ID 2405
  13. -- SELECT STATEMEN STARTS HERE
  14. SELECT COUNT(*) AS "Antal sager" FROM SAGER SAGER
  15. LEFT JOIN SAGSTYPER SAGSTYPER ON SAGER.SAGSTYPE_ID = SAGSTYPER.SAGSTYPE_ID
  16. LEFT JOIN PERSONER p ON sager.individ_id = p.individ_id
  17. LEFT JOIN kunde.bunkecpr b ON b.cpr = SUBSTR(p.cprnr,1,2)
  18. LEFT JOIN akasseenheder ae ON b.afdeling = ae.navn
  19. LEFT JOIN individ_afdelinger a ON a.akasse_afdeling = ae.individ_id
  20. WHERE 1=1
  21. AND p.individ_id = a.individ_id
  22. AND sagstyper.sagstype IN ('AJA','Samkøring')
  23. AND sager.sagsstatus = 'Aaben'
  24. AND
  25.     (EXISTS (SELECT 1 FROM arbejdsgange a, arbejdsgangstyper_v av, sager s
  26.     WHERE sager.individ_id = s.individ_id
  27.     AND s.sags_id = a.sags_id
  28.     AND a.arbejdsgangstype_id = av.arbejdsgangstype_id
  29.     AND av.navn = 'Indsigelse'
  30.     AND a.internstatus IN ('Aktiv','Ikke startet')
  31.     AND EXISTS (SELECT 1 FROM ydelseskort y
  32.         WHERE y.individ_id = s.individ_id
  33.         AND y.udbetalingstype = 'DP'
  34.         AND y.tildato = (SELECT MAX(y1.tildato) FROM ydelseskort y1 WHERE y1.individ_id = y.individ_id AND y1.status != 'ANN')))
  35. OR
  36.     EXISTS (SELECT 1 FROM ydelseskort yk, ydelseskort_status ys
  37.     WHERE yk.individ_id = sager.individ_id
  38.     AND yk.ydelseskort_id = ys.ydelseskort_id
  39.     AND yk.regulerings_id = ys.regulerings_id
  40.     AND yk.udbetalingstype = 'DP'
  41.     AND yk.status != 'ANN'
  42.     AND ys.status_kode = 'EJOK_OBJ'
  43.     AND ys.sekvensnr = (SELECT MAX(ys2.sekvensnr) FROM ydelseskort_status ys2 WHERE ys.ydelseskort_id=ys2.ydelseskort_id)))
  44. AND b.brugernavn = accountnames
  45. -- SELECT STATEMEN ENDS HERE
  46. END LOOP;
  47. END;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top