SELECT 
        pins.PIN, 
		orderdetails.ProductCode AS MEY_Order,
        pins.Manufacturer, 
		pins.SKU, 
        pins.Parent AS Sub, 
        orderdetails.ProductCode, 
        orderdetails.Quantity, 
        orderdetails.QtyOnHold, 
        orderdetails.QtyShipped, 
        pins.Cost,
        --ROUND(AVG(orderdetails.Vendor_Price),2) AS AVG_VP,
        orderdetails.ProductName, 
        orderdetails.OrderID, 
        orderdetails.ProductNote, 
        orderdetails.ShipDate, 
        orderdetails.OrderDetailID, 
        orders.orderstatus, 
        orders.OrderDate,
		orders.ShipState
FROM custopayted.orderdetails 
JOIN custopayted.orders 
        ON orders.OrderID = orderdetails.OrderID 
JOIN products.pins
		ON orderdetails.ProductCode = pins.ProductCode
JOIN products.vendor_map
                ON pins.ProductCode = vendor_map.ProductCode AND vendor_map.VendorCode = 'MEY'
WHERE orders.orderstatus = 'Processing'
AND orderdetails.QtyOnHold > 0 
GROUP BY 
        pins.PIN, 
        orderdetails.ProductCode, 
        pins.Manufacturer, 
        pins.SKU, 
        pins.Parent,
        orderdetails.Quantity, 
        orderdetails.QtyOnHold, 
        orderdetails.QtyShipped, 
        pins.Cost,
        orderdetails.ProductName, 
        orderdetails.OrderID, 
        orderdetails.ProductNote, 
        orderdetails.ShipDate, 
        orderdetails.OrderDetailID, 
        orders.orderstatus, 
        orderdetails.Vendor_Price,
        pins.Popularity,
        orders.OrderDate,
        orders.ShipState