fm_rem_sc.sql 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. select
  2. Betrieb,
  3. Stufe2,
  4. FAGNR,
  5. FTYPE,
  6. KNDNR,
  7. KNAME,
  8. Stufe5,
  9. REDAT,
  10. O500_HW2BUCHGBETR,
  11. FLDAT as FLDAT_von,
  12. FLDAT as FLDAT_bis,
  13. FLDAT,
  14. O500_MAHNSTUFE,
  15. Next_MAHNSTUFE,
  16. O500_HW2BETR_OFFEN,
  17. OPDAT,
  18. O500_BELEGNR1,
  19. Ktelf,
  20. Kstra,
  21. Kdplz,
  22. Kdort,
  23. Bemerkung,
  24. Wiedervorlage,
  25. Bemerkung_2,
  26. Bearbeitet,
  27. Mahnen,
  28. `User`,
  29. Aenderungsdatum,
  30. User_2,
  31. Aenderungsdatum_u2,
  32. KZALA,
  33. Versicherung,
  34. Rechtsanwalt,
  35. Reklamation,
  36. Selbstbeteiligung,
  37. SelbstbeteiligungBetrag,
  38. Mwst,
  39. MwstBetrag,
  40. Reserve_1,
  41. Reserve_3,
  42. round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) as "Faell_Tage",
  43. case
  44. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 14 ) then '0-2 Wochen'
  45. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 28 )then '2-4 Wochen'
  46. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 42 )then '4-6 Wochen'
  47. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) >= 42 ) then '> 6 Wochen'
  48. else 'n.v.'
  49. end as "Wochen"
  50. from fm_rem_report
  51. where stufe2 IN ('SC','TZ')
  52. and
  53. case
  54. when [userid] IN ('aet','afr','afo','asd','asf','asi','azn','bc','bsc','bz','ch','cbo','cgr','cho','cke','cki','cpe','cwd','de','dek','dfa','dfi','dki','dsu','eeb','ef','egi','eh','ekd','el','em','es','fau','fdo','fe','fgh','fhs','fhu','fsc','gcu',
  55. 'ge','gj','gk','hh','hce','hfr','hk','ho','ite','jal','jb','jhe','jhl','jkn','jmr','jg','jre',
  56. 'kh','kgr','kni','kta','kwe','kwi','lgi','lkr','lm','lre','lt','lwr','mb','mdi','mdk','me','mei','mf','mfr','mge','mgi','mmi','mop','msi','msu','mtr','mwe','nba','nf','nfi','ngu','nke','nna','nsa','nsc','nsm','nwa','obo','oke','ost','pkr','pma','psc','pwi',
  57. 'rhi','rm','ro','rr','sbr','sft','ssr','tre','skr','smr','spa','spe','ssh','sso','thg','tgn','tke','tkh','tno','ts','tsp','tze','var','vfe','vko','wb','we','wh','wk','wm','ws','wsc','yko','yun') then stufe2 IN ('SC')
  58. when [userid] IN ('ach','asa','atz','bs','bsr','cfo','cla','cle','cw','dbi','dwe','ead','esr','fs','gmo','js','kk','ksc','mae','lmo','man','mmz','msd','mrr','mvk','mvs','ng',
  59. 'or','pjr','psh','rcl','rti','sb','sd','se','sf','shu','sl','spr','ssg','st','sz','ta','thc','tl','tpa','tsa','tzg','tzw','usc','ut') then stufe2 IN ('TZ')
  60. else 1 end
  61. and
  62. case
  63. when [userid] IN ('sz') then betrieb IN ('VÖH','KRU','LL')
  64. when [userid] IN ('me') then betrieb IN ('VÖH','KRU','ULM')
  65. when [userid] IN ('ch','lre','ws') then betrieb IN ('MM','VÖH')
  66. when [userid] IN ('el','wsc') then betrieb IN ('MM','KRU')
  67. when [userid] IN ('nsa') then betrieb IN ('MM','KRU','GZ','LL','ULM')
  68. when [userid] IN ('ef') then betrieb IN ('MM','LL')
  69. when [userid] IN ('sd') then betrieb IN ('VÖH','KRU')
  70. when [userid] IN ('??') then betrieb IN ('GZ','KRU')
  71. when [userid] IN ('mvo', 'lmo') then betrieb IN ('GZ')
  72. when [userid] IN ('jb') then betrieb IN ('VÖH','ULM')
  73. when [userid] IN ('kh','wh') then betrieb IN ('KRU','ULM')
  74. when [userid] IN ('fe') then betrieb IN ('KRU','LL')
  75. when [userid] IN ('lgl') then betrieb IN ('ULM','KRU')
  76. when [userid] IN ('aet','afr','ag','asf','atz','bv','bsc','bsr','bz','cbo','cki','cpe','dek','dfa','egi','eh','es','fau','fhu','gcu','gk','hh','hk','jal','jg','js','jre','khe','kk','kni','kwi','ma','mmz','mrr','mrs','msu','mwe','nfi','ng','oke','pkr','pjr','pwi','rhi','rm','ro','sf','sl','smr','tke','tma','ut','we','yun') then betrieb IN ('MM')
  77. when [userid] IN ('gj','cw','st') then betrieb IN ('VÖH')
  78. when [userid] IN ('asd','dbi','shu','ssr','rr','rcl','jj','kkl','spe') then betrieb IN ('KRU')
  79. when [userid] IN ('afo','mmi','csi','dsu','mdi','ngu','ite','jhl','spr','vko') then betrieb IN ('GZ')
  80. when [userid] IN ('ach','asi','asl','awr','azn','bs','cgr','cla','cle','de','dfi','dki','dsm','dwe','ead','eeb','ekd','esr','fce','fgh','fs','fsc','gml','gmo','hce','hja','ho','jkn','jmr','kta','ksc','lgi','lbr','lkr','lt','lwr','mb','mdk','mei','mge','mgi','mtr','nba','nke','nf','nsm','nwa',
  81. 'obo','or','psc','psh','pz','rl','rti','sb','se','tre','sbr','ssg','sis','ta','tgn','thg','tkh','tno','tsa','tsp','tze','tzg','tzw','um','usc','vdu','vfe','vko','wb','wm') then betrieb IN ('ULM')
  82. when [userid] IN ('agr','ak','ala','asa','ash','bc','cfo','cho','cwd','dp','fdo','feb','fkn','hfr','jdr','jhe','kgr','kwe','lra','mae','man','mfr','mop','msd','msi','mvk','mvs','mzo','nna','nst','pma','sft','spa','ssh','thc','tl','tpa','ts','var','yko') then betrieb IN ('LL')
  83. else 1 end
  84. order by FLDAT asc