Hi @Evan_Purdy ,
@gpayne already pointed out the problem partially.
However it is not the BAQ really, it is how SQL works.
If you have SSMS installed, try these three:
1-
select
[Part].[Company] as [Part_Company],
[Part].[PartNum] as [Part_PartNum],
[Part].[PartDescription] as [Part_PartDescription],
[Part].[InActive] as [Part_InActive],
[Part].[UnitPrice] as [Part_UnitPrice],
[OrderDtl1].[RequestDate] as [OrderDtl1_RequestDate],
[OrderDtl1].[OrderNum] as [OrderDtl1_OrderNum]
from Erp.Part as Part
left outer join (select
[OrderDtl].[Company] as [OrderDtl_Company],
[OrderDtl].[PartNum] as [OrderDtl_PartNum],
(max(OrderDtl.OrderNum)) as [Calculated_LatestOrderNum]
from Erp.OrderDtl as OrderDtl
where (OrderDtl.VoidLine = 0)
group by [OrderDtl].[Company],
[OrderDtl].[PartNum]) as SubQuery1 on
Part.Company = SubQuery1.OrderDtl_Company
and Part.PartNum = SubQuery1.OrderDtl_PartNum
inner join Erp.OrderDtl as OrderDtl1 on
SubQuery1.OrderDtl_Company = OrderDtl1.Company
and SubQuery1.OrderDtl_PartNum = OrderDtl1.PartNum
and SubQuery1.Calculated_LatestOrderNum = OrderDtl1.OrderNum
2-
select
[Part].[Company] as [Part_Company],
[Part].[PartNum] as [Part_PartNum],
[Part].[PartDescription] as [Part_PartDescription],
[Part].[InActive] as [Part_InActive],
[Part].[UnitPrice] as [Part_UnitPrice],
[OrderDtl1].[RequestDate] as [OrderDtl1_RequestDate],
[OrderDtl1].[OrderNum] as [OrderDtl1_OrderNum]
from (select
[OrderDtl].[Company] as [OrderDtl_Company],
[OrderDtl].[PartNum] as [OrderDtl_PartNum],
(max(OrderDtl.OrderNum)) as [Calculated_LatestOrderNum]
from Erp.OrderDtl as OrderDtl
where (OrderDtl.VoidLine = 0)
group by [OrderDtl].[Company],
[OrderDtl].[PartNum]) as SubQuery1
right outer join Erp.Part as Part
on
Part.Company = SubQuery1.OrderDtl_Company
and Part.PartNum = SubQuery1.OrderDtl_PartNum
inner join Erp.OrderDtl as OrderDtl1 on
SubQuery1.OrderDtl_Company = OrderDtl1.Company
and SubQuery1.OrderDtl_PartNum = OrderDtl1.PartNum
and SubQuery1.Calculated_LatestOrderNum = OrderDtl1.OrderNum
3-
select
[Part].[Company] as [Part_Company],
[Part].[PartNum] as [Part_PartNum],
[Part].[PartDescription] as [Part_PartDescription],
[Part].[InActive] as [Part_InActive],
[Part].[UnitPrice] as [Part_UnitPrice],
[OrderDtl1].[RequestDate] as [OrderDtl1_RequestDate],
[OrderDtl1].[OrderNum] as [OrderDtl1_OrderNum]
from (select
[OrderDtl].[Company] as [OrderDtl_Company],
[OrderDtl].[PartNum] as [OrderDtl_PartNum],
(max(OrderDtl.OrderNum)) as [Calculated_LatestOrderNum]
from Erp.OrderDtl as OrderDtl
where (OrderDtl.VoidLine = 0)
group by [OrderDtl].[Company],
[OrderDtl].[PartNum]) as SubQuery1
inner join Erp.OrderDtl as OrderDtl1 on
SubQuery1.OrderDtl_Company = OrderDtl1.Company
and SubQuery1.OrderDtl_PartNum = OrderDtl1.PartNum
and SubQuery1.Calculated_LatestOrderNum = OrderDtl1.OrderNum
right outer join Erp.Part as Part
on
Part.Company = SubQuery1.OrderDtl_Company
and Part.PartNum = SubQuery1.OrderDtl_PartNum
You see the result, right? Why do you think the result is different?
Welcome to the SQL world
This is why I usually use CTE