I have been racking my brain on trying to figure out how to get this to work. Ive tried many different methods using subqueries and different types (except and innersubquery).
I am wanting to create a dashboard that will display all Jobs where they are Open and Released and have no material transactions, labor transactions, or subcontract activity. Then I want to pull the The first operation and display the op code. I am doing this to show jobs that have been released but have not been started.
All help is appreciated!
I know this is chaotic but this was as close as I could get and it’s not very quick with returns:
/*
- Disclaimer!!!
- This is not a real query being executed, but a simplified version for general vision.
- Executing it with any other tool may produce a different result.
*/
select
[JobHead].[JobNum] as [JobHead_JobNum],
[JobOps].[Calculated_FirstOpSeq] as [Calculated_FirstOpSeq]
from Erp.JobHead as JobHead
inner join (select
[JobOper].[Company] as [JobOper_Company],
[JobOper].[JobNum] as [JobOper_JobNum],
(min(JobOper.OprSeq)) as [Calculated_FirstOpSeq]
from Erp.JobOper as JobOper
inner join Erp.JobOper as JobOper1 on
JobOper.Company = JobOper1.Company
and JobOper.JobNum = JobOper1.JobNum
and JobOper.OprSeq = JobOper1.OprSeq
group by [JobOper].[Company],
[JobOper].[JobNum]) as JobOps on
JobHead.Company = JobOps.JobOper_Company
and JobHead.JobNum = JobOps.JobOper_JobNum
where (JobHead.JobClosed = FALSE and JobHead.JobReleased = TRUE)
and (not JobHead.JobNum = ANY (select LaborDtl_JobNum from ((select
[LaborDtl].[JobNum] as [LaborDtl_JobNum]
from Erp.LaborDtl as LaborDtl)) as LaborTrans) and not JobHead.JobNum = ANY (select PartTran_JobNum from ((select
[PartTran].[JobNum] as [PartTran_JobNum]
from Erp.PartTran as PartTran)) as PartTrans))