﻿CREATE VIEW [dbo].[WorkOrderStep] AS
SELECT wos.WorkOrderNumber,
       wos.WorkCenterCode,
       wos.StepNumber,
       wos.StepTypeCode,
       wos.BranchCode,
       wos.StepDescription,
       wos.StartDT,
       wos.EndDT,
       wos.FunctionCode,
	   fc.Description AS FunctionOperationDescription,
       wos.ScrappedQuantity,
       wos.LastUpdateDT
FROM
(SELECT hist.WorkOrderNumber,
       hist.WorkCenterCode,
       hist.StepNumber,
       hist.StepTypeCode,
       hist.BranchCode,
       hist.StepDescription,
       hist.StartDT,
       hist.EndDT,
       hist.FunctionCode,
       hist.ScrappedQuantity,
       hist.LastUpdateDT
FROM   dbo.WorkOrderStep_Hist hist
UNION ALL
SELECT curr.WorkOrderNumber,
       curr.WorkCenterCode,
       curr.StepNumber,
       curr.StepTypeCode,
       curr.BranchCode,
       curr.StepDescription,
       curr.StartDT,
       curr.EndDT,
       curr.FunctionCode,
       curr.ScrappedQuantity,
       curr.LastUpdateDT
FROM   dbo.WorkOrderStep_Curr curr 
) wos LEFT OUTER JOIN
dbo.FunctionCode fc ON (wos.FunctionCode = fc.Code)