SELECT
	DATE(o.OrderDate) AS 'Order Date',
	od.Orderid AS 'Order ID',
    od.OrderDetailID AS 'OrderDetail ID',
    od.ProductNote,
    od.ProductCode,
    od.QtyOnHold AS 'Quantity Needed',
    p.SKU,
    a.AlternateProductCode AS 'Alternate ProductCode',
    p2.PIN AS 'Alternate PIN',
    v.Location AS 'Alternate Location',
    v.Stock AS 'Warehouse Stock'
FROM custopayted.orders o
JOIN custopayted.orderdetails od ON o.orderid = od.orderid
JOIN products.pins p ON p.ProductCode = od.ProductCode
JOIN products.alternates a ON a.ProductCode = p.ProductCode
JOIN products.pins p2 ON p2.ProductCode = a.AlternateProductCode
JOIN products._VPW v ON p2.PIN = v.MFG_SKU
WHERE o.orderstatus = 'Processing'
  AND od.productcode IS NOT NULL
  AND p2.flags != 'w'
  AND od.qtyshipped = 0
  AND od.qtyonhold > 0
  AND od.qtyonpackingslip IS NULL
  AND v.TX > 0;