Views:

Our client wanted a Smartlist that shows a PO and the prices paid, along with the SOP document and the prices the item sold for. This view script was able to pull them together. We used it to create a Smartlist.

select POP.[PO Number], POP.[PO Line Status], POP.[Item Number], POP.[Item Description], POP.[Vendor ID],POP.[Vendor Name], POP.[Location Code],
POP.[QTY Ordered] [PO QTY Ordered], POP.[Unit Cost] [PO Unit Cost], POP.[Extended Cost] [PO Extended Cost], POP.[Buyer ID], POP.[Document Date],
POP.[PO Status], POP.[Project Number], POP.[QTY Canceled] [PO QTY Canceled], POP.[Remaining Subtotal],SOP.[SOP Number],SOP.[SOP Type], 
SOP.[Customer Name], SOP.[Customer Number], SOP.[Customer PO Number], SOP.[Document Amount], SOPL.[Unit Cost] [Sales Unit Cost], 
SOPL.[Extended Cost] [Sales Extended Cost], SOPL.[Unit Price], SOPL.[Extended Price] [Sales Extended Price], SOPL.QTY [Sales QTY] 
from PurchaseLineItems POP
LEFT JOIN
(select CASE SOPTYPE
WHEN 1 THEN 'Quote'
WHEN 2 THEN 'Order'
WHEN 3 THEN 'Invoice'
WHEN 4 THEN 'Return'
WHEN 5 THEN 'Back Order'
WHEN 6 THEN 'Fulfillment Order'
ELSE 'ERROR'
END SOPTYPE_TEXT, * from SOP60100) SOPPOP on SOPPOP.PONUMBER=POP.[PO Number] and SOPPOP.ORD=POP.Ord
LEFT JOIN 
SalesTransactions SOP on SOP.[SOP Number]=SOPPOP.SOPNUMBE and SOP.[SOP Type]=SOPPOP.SOPTYPE_TEXT
LEFT JOIN
SalesLineItems SOPL on SOPL.[SOP Number]=SOPPOP.SOPNUMBE and SOPL.[SOP Type]=SOPPOP.SOPTYPE_TEXT and SOPL.[Item Number]=POP.[Item Number]