KL_Hutchmfg
IS-IT--Management
I'm hoping that it's appropriate to post here. I'm working on my first SQL query and I am running into some issues on the "select" and not sure what I am doing wrong. Hoping someone could help. Here is a piece of it:
(Select qarNonConformanceCategoryID as WK2NC, count(qarNonConformanceCategoryID) as WK2_NonConformance, sum(lmlLaborHours) as WK2_TotalHours, sum(lmlLaborCost) + sum(lmlOverheadCost) as WK2_TotalCost,
case when count(qarNonConformanceCategoryID) <> 0 then count(qarNonConformanceCategoryID) else 0 end as WK2_NonConformance,
case when sum(lmlLaborHours) <>0 then sum(lmlLaborHours) else 0 end as WK2_TotalHours,
case when sum(lmlLaborCost) <> 0 then sum(lmlLaborCost) else 0 end, case when sum(lmlOverheadCost) <> 0 then sum(lmlOverheadCost) else 0 end as WK2_TotalCost
from NonConformances where qarJobID
(Select lmlTimecardID from TimecardLines where datepart(ww,lmlActualStartTime) = datepart(ww,Getdate()) -1 and datepart(yy,lmlActualStartTime) = datepart(yy,Getdate()) and lmlJobID = qarJobID and lmlJobAssemblyID = qarJobAssemblyID and lmlJobOperationID = qarJobOperationID and
lmlTimecardID = (select top 1 lmlTimecardID from TimecardLines where lmlJobID = qarJobID and lmlJobAssemblyID = qarJobAssemblyID and lmlJobOperationID = qarJobOperationID Order By lmlActualStartTime desc))
group by qarNonConformanceCategoryID) as WK2 on WK2NC = qarNonConformanceCategoryID
Left Outer Join
Bolded is where I am getting errors. Any ideas as to why?
(Select qarNonConformanceCategoryID as WK2NC, count(qarNonConformanceCategoryID) as WK2_NonConformance, sum(lmlLaborHours) as WK2_TotalHours, sum(lmlLaborCost) + sum(lmlOverheadCost) as WK2_TotalCost,
case when count(qarNonConformanceCategoryID) <> 0 then count(qarNonConformanceCategoryID) else 0 end as WK2_NonConformance,
case when sum(lmlLaborHours) <>0 then sum(lmlLaborHours) else 0 end as WK2_TotalHours,
case when sum(lmlLaborCost) <> 0 then sum(lmlLaborCost) else 0 end, case when sum(lmlOverheadCost) <> 0 then sum(lmlOverheadCost) else 0 end as WK2_TotalCost
from NonConformances where qarJobID
(Select lmlTimecardID from TimecardLines where datepart(ww,lmlActualStartTime) = datepart(ww,Getdate()) -1 and datepart(yy,lmlActualStartTime) = datepart(yy,Getdate()) and lmlJobID = qarJobID and lmlJobAssemblyID = qarJobAssemblyID and lmlJobOperationID = qarJobOperationID and
lmlTimecardID = (select top 1 lmlTimecardID from TimecardLines where lmlJobID = qarJobID and lmlJobAssemblyID = qarJobAssemblyID and lmlJobOperationID = qarJobOperationID Order By lmlActualStartTime desc))
group by qarNonConformanceCategoryID) as WK2 on WK2NC = qarNonConformanceCategoryID
Left Outer Join
Bolded is where I am getting errors. Any ideas as to why?