I have the following script that fails when i un-rem the S1.TOT_QTY line with the error -
Msg 102, Level 15, State 1, Line 11
Incorrect syntax near 'S1'.
Msg 102, Level 15, State 1, Line 24
Incorrect syntax near 'S1'.
runs fine is remarked out - I just don't get the totals
select
B.vendID Vendor_ID,
C.VENDNAME Vendor_Name,
B.USER01 Contract_Number,
A.VendPartNbr Vender_Part,
A.ItemId BHM_Part,
B.Description Description,
B.PoUnit UOM,
B.Price Price
-- S1.Tot_Qty Total_Qty
from XW_Item_Vendor A
join XW_item B
on B.ID = A.ItemID
join PM00200 C
on C.VENDORID = B.VendId
join
(select ITEMNMBR, sum(sub.QTYORDER) as 'Tot_Qty'
from
(select
ITEMNMBR, DOCDATE, QTYORDER from (select * from slbPurchaseOrderLines with (NOLOCK)) T1
Where DOCDATE between '01/01/2018' and '12/31/2018') sub
Group by sub.ITEMNMBR) S1
on S1.ITEMNMBR = A.VendPartNbr
What am I missing ???