select distinct
[LaborDtl].[JobNum] as [LaborDtl_JobNum],
[SNTran].[PartNum] as [SNTran_PartNum],
[SNTran].[SerialNumber] as [SNTran_SerialNumber],
[LaborDtl].[OprSeq] as [LaborDtl_OprSeq],
[LaborDtl].[EmployeeNum] as [LaborDtl_EmployeeNum],
[LaborDtl].[ClockInDate] as [LaborDtl_ClockInDate],
[LaborDtl].[ClockinTime] as [LaborDtl_ClockinTime],
[LaborDtl].[ClockOutTime] as [LaborDtl_ClockOutTime]
from Erp.LaborDtl as LaborDtl
inner join Erp.SNTran as SNTran on
LaborDtl.Company = SNTran.Company
and LaborDtl.JobNum = SNTran.JobNum
and LaborDtl.OprSeq = SNTran.OprSeq
and LaborDtl.AssemblySeq = SNTran.AssemblySeq
and ( SNTran.TranType = ‘OPR-CMP’ or SNTran.TranType = ‘OPR-RWK’ )
where (LaborDtl.JobNum = ‘CT481-JIS-001’ and LaborDtl.EmployeeNum = ‘740’)
for got to remove to the distinct but the result is still the same.
select
[LaborDtl].[JobNum] as [LaborDtl_JobNum],
[SNTran].[PartNum] as [SNTran_PartNum],
[SNTran].[SerialNumber] as [SNTran_SerialNumber],
[LaborDtl].[OprSeq] as [LaborDtl_OprSeq],
[LaborDtl].[EmployeeNum] as [LaborDtl_EmployeeNum],
[LaborDtl].[ClockInDate] as [LaborDtl_ClockInDate],
[LaborDtl].[ClockinTime] as [LaborDtl_ClockinTime],
[LaborDtl].[ClockOutTime] as [LaborDtl_ClockOutTime]
from Erp.LaborDtl as LaborDtl
inner join Erp.SNTran as SNTran on
LaborDtl.Company = SNTran.Company
and LaborDtl.JobNum = SNTran.JobNum
and LaborDtl.OprSeq = SNTran.OprSeq
and LaborDtl.AssemblySeq = SNTran.AssemblySeq
and ( SNTran.TranType = ‘OPR-CMP’ or SNTran.TranType = ‘OPR-RWK’ )
where (LaborDtl.JobNum = ‘CT481-JIS-001’ and LaborDtl.EmployeeNum = ‘740’)
Agree with @Banderson the order does not matter with inner joins. Have you queried separately yet to see the records not connected that are you trying to connect?
Does your expected join fields match each other when queried separately? I know simple question, but not seeing the data is kind of hard to step through it.
OK calling it a night, but have you tried the subquery option. Change this part of your query, Erp.SNTran as SNTran, to something like this… I have not done this in the BAQ builder so I am not sure the steps.
select Company, SerailNo, TranType, JobNum, AssemblySeq, max(trandate) as TranDate (if trandate is in the table)
from SNTran
where (TranType = ‘OPR-CMP’ or TranType = ‘OPR-RWK’)
Group by Company, SerialNo, Trantype, JobNum, AssemblySeq
This should give you a single record per day for each of those fields. If you want just one record drop the trandate field.
This becomes a subset of group data to link in as your table. It will cut down on the multiple records you are picking up when adding in SNTran.
I think your original query was just fine. All you needed was the assembly sequence, you were getting multiples because there were multiple assembly sequences on the job with the same part number. Here’s the query that I think should work, minus the filters. You will probably want to leave those off your BAQ as you will add trackers in you dashboard anyways.
select
[LaborDtl].[JobNum] as [LaborDtl_JobNum],
[JobOper].[PartNum] as [JobOper_PartNum],
[SNTran].[SerialNumber] as [SNTran_SerialNumber],
[LaborDtl].[EmployeeNum] as [LaborDtl_EmployeeNum],
[LaborDtl].[ClockInDate] as [LaborDtl_ClockInDate],
[LaborDtl].[ClockinTime] as [LaborDtl_ClockinTime],
[LaborDtl].[Company] as [LaborDtl_Company]
from Erp.LaborDtl as LaborDtl
inner join Erp.JobOper as JobOper on
LaborDtl.Company = JobOper.Company
and LaborDtl.JobNum = JobOper.JobNum
and LaborDtl.AssemblySeq = JobOper.AssemblySeq
and LaborDtl.OprSeq = JobOper.OprSeq
inner join Erp.SNTran as SNTran on
JobOper.Company = SNTran.Company
and JobOper.JobNum = SNTran.JobNum
and JobOper.AssemblySeq = SNTran.AssemblySeq
and JobOper.PartNum = SNTran.PartNum