0 THEN VndrPrt.[CostPerUnit]
ELSE ISNULL(AffItm.[CostPerUnit], 0)
END AS [Cost]
,VndrPrt.[DefaultUOM] AS [UOM]
,PrtDetail.[LeadTime] AS [LeadTime]
,CASE
WHEN (ROW_NUMBER() OVER (PARTITION BY AI.[LineNumber] ORDER BY SrcList.[Number],VndrPrt.[Owner],VndrPrt.[Number]) = 1) THEN 'true'
ELSE 'false'
END AS [DefaultVendor]
,PrtDetail.[MinimumOrderQuantity] AS [MinQty]
,SrcList.[Number] AS [Rank]
,AI.[LineNumber] AS [AffectedLine]
FROM
Change_View Chg
INNER JOIN AffectedItem_View AI ON AI.[ChangeAction] = Chg.[Id]
INNER JOIN viewer.ItemView AffItm ON AffItm.[ItemId] = AI.[Item]
INNER JOIN SourceItem_View SrcList ON SrcList.[ParentItem] = AffItm.[ItemId]
AND SrcList.[FromNum] <= Chg.[ChangeNum] AND SrcList.[ToNum] > Chg.[ChangeNum]
INNER JOIN BasicItemRevision_View VndrPrtRev ON VndrPrtRev.[ItemId] = SrcList.[BasicItem]
AND VndrPrtRev.[FromNum] <= Chg.[ChangeNum] AND VndrPrtRev.[ToNum] > Chg.[ChangeNum]
INNER JOIN viewer.ItemView VndrPrt ON VndrPrt.[ItemId] = VndrPrtRev.[ItemId]
INNER JOIN Part_View PrtDetail ON PrtDetail.[Id] = VndrPrtRev.[ItemId]
WHERE
Chg.[Id] = @P1
AND AffItm.[IsHomeItem] = 'true'
AND Chg.[State] >= 10
) PartRows
ORDER BY
[FishbowlPartNumber],[Vendor],[VendorPartNumber]
]]>
Table2