Text: Incorrect syntax near 'Erp'

I have looked through everything I can think of, and cannot figure out this syntax error. anyone see anything that I am missing?

Error: Text: Incorrect syntax near ‘Erp’.

Code:
select
[OrderHed].[OpenOrder] as [OrderHed_OpenOrder],
[OrderDtl].[OpenLine] as [OrderDtl_OpenLine],
[OrderHed].[OrderNum] as [OrderHed_OrderNum],
[OrderDtl].[OrderLine] as [OrderDtl_OrderLine],
[OrderDtl].[PartNum] as [OrderDtl_PartNum],
[OrderHed].[CustNum] as [OrderHed_CustNum],
[OrderHed].[PONum] as [OrderHed_PONum],
[OrderDtl].[RequestDate] as [OrderDtl_RequestDate],
[OrderHed].[RequestDate] as [OrderHed_RequestDate],
[OrderDtl].[OrderQty] as [OrderDtl_OrderQty],
[OrderRel].[SellingReqQty] as [OrderRel_SellingReqQty],
[SubQuery2].[Calculated_SumOfOnHandQty] as [Calculated_SumOfOnHandQty],
[OrderDtl].[LineType] as [OrderDtl_LineType],
[OrderDtl].[LineDesc] as [OrderDtl_LineDesc],
[OrderDtl].[ProdCode] as [OrderDtl_ProdCode],
[OrderRel].[OrderRelNum] as [OrderRel_OrderRelNum],
[OrderRel].[OurStockShippedQty] as [OrderRel_OurStockShippedQty],
((OrderRel.SellingReqQty - OrderRel.OurStockShippedQty)) as [Calculated_RemainingQTY]
from Erp.OrderHed as OrderHed
inner join Erp.OrderDtl as OrderDtl on
OrderHed.Company = OrderDtl.Company
And
OrderHed.OrderNum = OrderDtl.OrderNum
and ( OrderDtl.OpenLine = true )

inner join Erp.OrderRel as OrderRel on
OrderRel.Company = OrderDtl.Company
And
OrderRel.OrderNum = OrderDtl.OrderNum
And
OrderRel.OrderLine = OrderDtl.OrderLine
and ( OrderRel.OpenRelease = true )

inner join (select
[Part].[PartNum] as [Part_PartNum],
(sum( PartWhse.OnHandQty )) as [Calculated_SumOfOnHandQty],
[Part].[Company] as [Part_Company]
from Erp.Part as Part
inner join Erp.PartWhse as PartWhse on
Part.Company = PartWhse.Company
And
Part.PartNum = PartWhse.PartNum

group by [Part].[PartNum],
[Part].[Company]) as SubQuery2 on
OrderDtl.Company = SubQuery2.Part_Company

OrderDtl.PartNum = SubQuery2.Part_PartNum

where (OrderHed.OpenOrder = true)

You should be able to stick it in SQL studio and see where the error is

Jos? C Gomez
Senior Software Engineer

You are missing an “AND” on your join to Subquery2

Thank you very much. Not sure when that got removed, but it works great now.