SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE   VIEW [transform_ims].[Serviceberater_Rechnung] AS
SELECT DISTINCT [T1]."invoice_type" AS "Invoice Type"
              , [T1]."invoice_number" AS "Invoice Number"
              , [T2]."order_taking_employee_no" AS "Order Taking Employee No"
              , [T2]."order_delivery_employee_no" AS "Order Delivery Employee No"
              , [T1]."invtype_invnr" AS "Invoice_Type_Invoice_Number"
              , [T3]."employee_number" AS "Employee Number_Employees"
              , [T3]."name" AS "Name_Employees"
              , left([T3]."employee_number", 4) + ' - ' + [T3]."name" AS "Serviceberater"
FROM [LOCOSOFT].[dbo].[order_positions] [T2]
         LEFT JOIN [LOCOSOFT].[dbo].[invoices] [T1] ON [T2]."order_number" = [T1]."order_number"
         LEFT JOIN [LOCOSOFT].[dbo].[employees] [T3] ON [T2]."order_taking_employee_no" = [T3]."employee_number"

WHERE [T1]."invoice_type" BETWEEN 2 AND 6
  AND [T2]."order_date" >= convert(datetime, '2019-01-01T00:00:00.000')
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
