Zeit_ben_Std_LG.sql 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 (
  26. PARTITION BY "Order Number",
  27. "Mechanic No_Labours"
  28. ) AS "Min_Invoice_Date"
  29. FROM (
  30. SELECT "Order Number",
  31. '' AS "Labour Type",
  32. '' AS "Code_Labour_Types",
  33. '' AS "Description_Labour_Types",
  34. "Order Number_Labours",
  35. "Subsidiary_Labours",
  36. 0 AS "Invoice Type_Labours",
  37. "Mechanic No_Labours",
  38. 10 AS "AW/Std.",
  39. 'ben. Std.' AS "Zeitkategorie",
  40. '' AS "Zeitkategorie2",
  41. "Employee Number_Employee",
  42. "Name_Employee",
  43. "Monteur",
  44. "Invoice Date_Invoices",
  45. "Invoice Date_Invoices" AS "Datum",
  46. "Duration Minutes_Times",
  47. "ben. Std.",
  48. 0 AS "Invoice Number",
  49. "Is Canceled",
  50. "Cancelation Number",
  51. "Cancelation Date",
  52. "Start Time",
  53. "End Time",
  54. MIN("Invoice Date_Invoices") OVER (
  55. PARTITION BY "Order Number",
  56. "Mechanic No_Labours"
  57. ) AS c26
  58. FROM (
  59. SELECT T2."mechanic_no" AS "Mechanic No_Labours",
  60. T1."order_number" AS "Order Number",
  61. T5."end_time" AS "End Time",
  62. T5."start_time" AS "Start Time",
  63. T4."cancelation_date" AS "Cancelation Date",
  64. T4."cancelation_number" AS "Cancelation Number",
  65. T4."is_canceled" AS "Is Canceled",
  66. (T5."exact_duration_seconds" / 60) / 60 AS "ben. Std.",
  67. T5."exact_duration_seconds" / 60 AS "Duration Minutes_Times",
  68. T4."invoice_date" AS "Invoice Date_Invoices",
  69. (rtrim((((T3."employee_number"))))) + ' - ' + T3."name" AS "Monteur",
  70. T3."name" AS "Name_Employee",
  71. T3."employee_number" AS "Employee Number_Employee",
  72. '0' + (rtrim((((T3."subsidiary"))))) AS "Subsidiary_Labours",
  73. T2."order_number" AS "Order Number_Labours"
  74. FROM "LOCOSOFT"."dbo"."times" T5,
  75. (
  76. "dbo"."invoices" T4 LEFT JOIN (
  77. (
  78. "dbo"."order_positions" T1 LEFT JOIN "dbo"."labours" T2 ON T1."order_number" = T2."order_number"
  79. ) LEFT JOIN "dbo"."employees" T3 ON T2."mechanic_no" = T3."employee_number"
  80. ) ON (T2."invoice_number" = T4."invoice_number")
  81. AND (T2."invoice_type" = T4."invoice_type")
  82. )
  83. WHERE (
  84. (T2."order_number" = T5."order_number")
  85. AND (T2."mechanic_no" = T5."employee_number")
  86. )
  87. AND (((convert(FLOAT, T2."time_units"))) <> 0)
  88. ) D2
  89. ) D1
  90. WHERE (c26 = "Invoice Date_Invoices")
  91. -- order by "Order Number" asc,"Mechanic No_Labours" asc,"Start Time" asc