Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query Help

Status
Not open for further replies.

KL_Hutchmfg

IS-IT--Management
May 2, 2018
18
US
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?
 
Hi,

You want to state,

where qarJobID

...then you need an operator like = or IN to compare to the value returned by your other SELECT enclosed in ().

So that part of your SQL might look like this...
Code:
...
from NonConformances where qarJobID =
(Select lmlTimecardID from TimecardLines......
...)

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Okay. That makes sense. So I essentially need the qarJobID from NonConformances to = the lmlJobID in the Timecardlines. How would or should I write that then? I tried from NonConformances where qarJobID = lmlJobID from Timecardlines but it gave me an error on the from.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top