-1
我想根據WorkCentres加入2個表。在一個表中,該字段稱爲LWorkCentre,在另一個表中稱爲WorkCentre。從2個表中返回數據並過濾出信息
我已經完成了一個Full Outer Join來加入這兩個表。然後我想根據加班工作中心返回加班時間。因此,在加班WorkCentre適用的情況下,返回運行時間,否則返回0.
這就是我如何編寫視圖,但是它沒有返回任何值。 請幫助我不知道我要去哪裏錯了。
SELECT DISTINCT
dbo.PrjJobHierDet.JobEstimate AS CONTRACT,
dbo.PrjContMaster.ContractDesc1 AS CONTRACT_NAME,
dbo.WipJobPost.TrnDate AS DATE,
dbo.WipJobPost.LWorkCentre AS WORKCENTRE,
dbo.WipJobPost.LWorkCentreDesc AS WORKCENTRE_DESC,
dbo.WipJobPost.Hierarchy1 AS SECTION,
dbo.WipJobPost.Hierarchy2 AS HIER,
dbo.WipJobPost.LEmployee AS EMPLOYEE_ID,
dbo.BomEmployee.Name AS EMPLOYEE_NAME,
dbo.WipJobPost.LRunTimeHours AS HOURS_WORKED,
dbo.BomEmployee.MtdActProdHours AS PRODUCTION_HOURS,
dbo.BomEmployee.MtdNonProdHours AS STANDING_TIME_HOURS,
dbo.BomEmployee.StdHrsPerMonth AS BUDGETED_HOURS,
CASE
WHEN LWorkCentre = 'CCOTAR' THEN LRunTimeHours
WHEN LWorkCentre != 'CCOTAR' THEN 0
WHEN LWorkCentre = 'CCOTWI' THEN LRunTimeHours
WHEN LWorkCentre != 'CCOTWI' THEN 0
WHEN LWorkCentre = 'CCOTPM' THEN LRunTimeHours
WHEN LWorkCentre != 'CCOTPM' THEN 0
WHEN LWorkCentre = 'CCOTLA' THEN LRunTimeHours
WHEN LWorkCentre != 'CCOTLA' THEN 0
WHEN LWorkCentre = 'CCOTSA' THEN LRunTimeHours
WHEN LWorkCentre != 'CCOTSA' THEN 0
WHEN LWorkCentre = 'CCOTSU' THEN LRunTimeHours
WHEN LWorkCentre != 'CCOTSU' THEN 0
WHEN LWorkCentre = 'ELOTAD' THEN LRunTimeHours
WHEN LWorkCentre != 'ELOTAD' THEN 0
WHEN LWorkCentre = 'ELOTCA' THEN LRunTimeHours
WHEN LWorkCentre != 'ELOTCA' THEN 0
WHEN LWorkCentre = 'ELOTDE' THEN LRunTimeHours
WHEN LWorkCentre != 'ELOTDE' THEN 0
WHEN LWorkCentre = 'MAOTFA' THEN LRunTimeHours
WHEN LWorkCentre != 'MAOTFA' THEN 0
END AS Overtime
FROM dbo.PrjJobHierDet
INNER JOIN dbo.WipJobPost
ON dbo.PrjJobHierDet.JobEstimate = dbo.WipJobPost.Job
INNER JOIN dbo.PrjContMaster
ON dbo.PrjContMaster.Contract = dbo.WipJobPost.Job
INNER JOIN dbo.BomEmployee
ON dbo.BomEmployee.Employee = dbo.WipJobPost.LEmployee
FULL OUTER JOIN dbo.BomWorkCentre
ON dbo.WipJobPost.LWorkCentre = BomWorkCentre.WorkCentre