SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE VIEW [transform_imr].[zeit_stempelungen_neu]
AS
SELECT [T1]."employee_number" AS "Employee Number_Employees"
     , [T1]."name" AS "Name_Employees"
     , [T1]."initials" AS "Initials_Employees"
     , [T1]."mechanic_number" AS "Mechanic Number_Employees"
     , [T1]."salesman_number" AS "Salesman Number_Employees"
     , [T1]."employment_date" AS "Employment Date_Employees"
     , [T1]."termination_date" AS "Termination Date_Employees"
     , [T1]."leave_date" AS "Leave Date_Employees"
     , [T2]."employee_number" AS "Employee Number_Times"
     , [T2]."order_number" AS "Order Number_Times"
     , [T2]."start_time" AS "Start Time_Times"
     , [T2]."type" AS "Type_Times"
     , [T3]."Order Number" AS "Order Positions_Times"
     , [T2]."end_time" AS "End Time_Times"
     , convert(float, [T2]."exact_duration_seconds") / 60 AS "Duration Minutes_Times"
     , [T4]."type" AS "Type_Time_Types"
     , [T4]."description" AS "Description_Time_Types"
     , [T2]."start_time" AS "Datum"
     , '1' AS "Hauptbetrieb"
     , (trim((convert(varchar(50), [T1]."subsidiary")))) AS "Standort"
     , (trim((convert(varchar(50), [T1]."employee_number")))) + ' - ' + [T1]."name" AS "Monteur"
     , CASE
           WHEN ([T4]."type" = 1)
               THEN ((convert(float, [T2]."exact_duration_seconds") / 60) / 60)
           ELSE (0)
       END AS "Anwesenheit"
     , CASE
           WHEN ([T4]."type" = 2)
               THEN ((convert(float, [T2]."exact_duration_seconds") / 60) / 60)
           ELSE (0)
       END AS "produktiv"
     , CASE
           WHEN ([T4]."type" = 1)
               THEN ((convert(float, [T2]."exact_duration_seconds") / 60) / 60)
           ELSE (0)
       END AS "unproduktiv"
     , CASE
           WHEN ([T2]."type" = 2)
               THEN ('produktiv')
           ELSE ('unproduktiv')
       END AS "Zeitkategorie"
     , '' AS "Zeitkategorie2"
     , (convert(float, [T2]."exact_duration_seconds") / 60) / 60 AS "Ges. Std."
     , [T2]."order_number" AS "Order Number"
     , (datepart(WEEKDAY, [T2]."start_time")) AS "Wochentag_Datum"
     , [T1]."is_flextime" AS "Is Flextime_Employees"
     , [T1]."break_time_registration" AS "Break Time Registration_Employees"
FROM [LOCOSOFT]."dbo"."employees" [T1]
         INNER JOIN [LOCOSOFT]."dbo"."times" [T2] ON ([T1]."employee_number" = [T2]."employee_number")
         LEFT OUTER JOIN [LOCOSOFT]."dbo"."time_types" [T4] ON [T2]."type" = [T4]."type"
         LEFT OUTER JOIN [transform_ims]."offene_Auftraege_Ums_ben_AW_fuer_Monteure" [T3] ON [T3]."order number_ori" = [T2]."order_number"
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
