我正在尝试基于WorkCentres加入2个表。在一个表中,该字段称为LWorkCentre,在另一个表中称为WorkCentre。
我已经完成了一个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
答案 0 :(得分:0)
根据查询,只有在内部联接中没有可加入的数据才有意义。
这两个表是否会在同一个字段上加入?
INNER JOIN dbo.WipJobPost
ON dbo.PrjJobHierDet.JobEstimate = dbo.WipJobPost.Job
INNER JOIN dbo.PrjContMaster
ON dbo.PrjContMaster.Contract = dbo.WipJobPost.Job
如果不知道您的数据的结构如何,请尝试将内部联接切换为LEFT OUTER JOIN
以确定其未正确加入的原因