fm_rem_naga.sql 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. ZA_1,
  17. ZA_2,
  18. ZA_3,
  19. O500_HW2BETR_OFFEN,
  20. OPDAT,
  21. O500_BELEGNR1,
  22. Ktelf,
  23. Kstra,
  24. Kdplz,
  25. Kdort,
  26. Bemerkung,
  27. Wiedervorlage,
  28. Bemerkung_2,
  29. Bearbeitet,
  30. Mahnen,
  31. `User`,
  32. Aenderungsdatum,
  33. User_2,
  34. Reklamation,
  35. Aenderungsdatum_u2,
  36. geplAuslief_NA,
  37. Auslief_NA,
  38. geplAuslief_GA,
  39. Auslief_GA,
  40. LKNAME,
  41. LKTELF,
  42. LKSTRA,
  43. LKDPLZ,
  44. LKDORT,
  45. Reserve_1,
  46. Reserve_3,
  47. shipment_date,
  48. customer_number_leasing,
  49. customer_name_leasing,
  50. text1,
  51. text2,
  52. round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) as "Faell_Tage",
  53. case
  54. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 14 ) then '0-2 Wochen'
  55. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 28 )then '2-4 Wochen'
  56. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 42 )then '4-6 Wochen'
  57. when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) >= 42 ) then '> 6 Wochen'
  58. else 'n.v.'
  59. end as "Wochen"
  60. from fm_rem_report
  61. where stufe2 NOT IN ('SC','TZ','RA')
  62. and
  63. case
  64. when [userid] IN ('aba','bwo','mba','sop') then stufe2 IN ('NA')
  65. when [userid] IN ('hko','sc','sv','fpo','fda') then stufe2 IN ('GA')
  66. else 1 end
  67. and
  68. case
  69. when [userid] IN ('mh') then betrieb IN ('MM','VÖH','KRU','ULM')
  70. when [userid] IN ('mc') then betrieb IN ('MM','VÖH','KRU','LL')
  71. when [userid] IN ('mj') then betrieb IN ('MM','KRU','ULM','LL')
  72. when [userid] IN ('hg') then betrieb IN ('VÖH','KRU','ULM','LL')
  73. when [userid] IN ('??') then betrieb IN ('MM','LL')
  74. when [userid] IN ('be') then betrieb IN ('VÖH','KRU')
  75. when [userid] IN ('mba') then betrieb IN ('MM','KRU')
  76. when [userid] IN ('??') then betrieb IN ('GZ','KRU')
  77. when [userid] IN ('mvo') then betrieb IN ('GZ')
  78. when [userid] IN ('aho','azh','bv','fpo','hko','jlt','jsh','jti','mga','sc','sko','sop') then betrieb IN ('MM')
  79. when [userid] IN ('mba','kkl') then betrieb IN ('KRU')
  80. when [userid] IN ('asl','bta','bwo','fda','lho','mn','mne','mvo','nba','rl','rp','son','ssu','tbo','um','vb','vs') then betrieb IN ('ULM')
  81. when [userid] IN ('ak','ala','ash','bb','dp','jdr','muy','mzo','nst','rhe','skr','sv','ype') then betrieb IN ('LL')
  82. when [userid] IN ('cab','fd','aho','mk','ka','fl','tb','gr','kgu','hbo','sbe','hp',
  83. 'fja','jja','twa','sdo','tbe','ba','af','vpo','mku','rwo','osa','ipl',
  84. 'sse','rze','aan','tal','wr','mma') then kdbnr = [userid]
  85. else 1 end
  86. order by FLDAT asc