Zeit_ben_Std_LG.sql 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. select distinct "Order Number" as "Order Number",
  2. "Labour Type" as "Labour Type",
  3. "Code_Labour_Types" as "Code_Labour_Types",
  4. "Description_Labour_Types" as "Description_Labour_Types",
  5. "Order Number_Labours" as "Order Number_Labours",
  6. "Subsidiary_Labours" as "Subsidiary_Labours",
  7. "Invoice Type_Labours" as "Invoice Type_Labours",
  8. "Mechanic No_Labours" as "Mechanic No_Labours",
  9. "AW/Std." as "AW/Std.",
  10. "Zeitkategorie" as "Zeitkategorie",
  11. "Zeitkategorie2" as "Zeitkategorie2",
  12. "Employee Number_Employee" as "Employee Number_Employee",
  13. "Name_Employee" as "Name_Employee",
  14. "Monteur" as "Monteur",
  15. "Invoice Date_Invoices" as "Invoice Date_Invoices",
  16. "Datum" as "Datum",
  17. "Duration Minutes_Times" as "Duration Minutes_Times",
  18. "ben. Std." as "ben. Std.",
  19. "Invoice Number" as "Invoice Number",
  20. "Is Canceled" as "Is Canceled",
  21. "Cancelation Number" as "Cancelation Number",
  22. "Cancelation Date" as "Cancelation Date",
  23. "Start Time" as "Start Time",
  24. "End Time" as "End Time",
  25. MIN("Invoice Date_Invoices") OVER (partition by "Order Number","Mechanic No_Labours") as "Min_Invoice_Date"
  26. from
  27. (select c31 as "Order Number",
  28. '' as "Labour Type",
  29. '' as "Code_Labour_Types",
  30. '' as "Description_Labour_Types",
  31. c44 as "Order Number_Labours",
  32. c43 as "Subsidiary_Labours",
  33. 0 as "Invoice Type_Labours",
  34. c30 as "Mechanic No_Labours",
  35. 10 as "AW/Std.",
  36. 'ben. Std.' as "Zeitkategorie",
  37. '' as "Zeitkategorie2",
  38. c42 as "Employee Number_Employee",
  39. c41 as "Name_Employee",
  40. c40 as "Monteur",
  41. c39 as "Invoice Date_Invoices",
  42. c39 as "Datum",
  43. c38 as "Duration Minutes_Times",
  44. c37 as "ben. Std.",
  45. 0 as "Invoice Number",
  46. c36 as "Is Canceled",
  47. c35 as "Cancelation Number",
  48. c34 as "Cancelation Date",
  49. c33 as "Start Time",
  50. c32 as "End Time",
  51. MIN(c39) OVER (partition by c31,c30) as c26
  52. from
  53. (select T2."mechanic_no" as c30,
  54. T1."order_number" as c31,
  55. T5."end_time" as c32,
  56. T5."start_time" as c33,
  57. T4."cancelation_date" as c34,
  58. T4."cancelation_number" as c35,
  59. T4."is_canceled" as c36,
  60. (T5."exact_duration_seconds" / 60) / 60 as c37,
  61. T5."exact_duration_seconds" / 60 as c38,
  62. T4."invoice_date" as c39,
  63. (rtrim((convert(varchar(50), T3."employee_number")))) + ' - ' + T3."name" as c40,
  64. T3."name" as c41,
  65. T3."employee_number" as c42,
  66. '0' + (rtrim((convert(varchar(50), T3."subsidiary")))) as c43,
  67. T2."order_number" as c44
  68. from "LOCOSOFT"."dbo"."times" T5,
  69. ("dbo"."invoices" T4 left outer join (("dbo"."order_positions" T1 left outer join "dbo"."labours" T2 on T1."order_number" = T2."order_number") left outer join "dbo"."employees" T3 on T2."mechanic_no" = T3."employee_number") on (T2."invoice_number" = T4."invoice_number") and (T2."invoice_type" = T4."invoice_type"))
  70. where ((T2."order_number" = T5."order_number") and (T2."mechanic_no" = T5."employee_number"))
  71. and (((convert(float, T2."time_units"))) <> 0)
  72. ) D2
  73. ) D1
  74. where (c26 = "Invoice Date_Invoices")
  75. -- order by "Order Number" asc,"Mechanic No_Labours" asc,"Start Time" asc