SELECT 
	o.qline,
	o.part,
	o.touched,
	o.qcustomer,
    lp.customer,
    lp.mold,
    p.[key] AS part,  -- this is the part number
    j.qty,
    j.price,
    j.odate,
    j.ordnum,
    j.quoten
FROM 
	rlarp.live_quotes o
	LEFT OUTER JOIN pricing.lastprice lp ON 
		lp.customer = o.qcustomer 
		AND lp.mold = substring(o.part,1,8)
	OUTER APPLY OPENJSON(lp.part_stats) AS p  -- unpacks part keys
	OUTER APPLY OPENJSON(p.value) 
	    WITH (
	        qty     FLOAT,
	        price   FLOAT,
	        odate   DATE,
	        ordnum  INT,
	        quoten  INT
	    ) AS j
WHERE 	
	qid = 112859
	AND o.part = p.[key] COLLATE SQL_Latin1_General_CP1_CI_AS
	
	
SELECT 
	o.qline,
	o.part,
	o.touched
FROM 
	rlarp.live_quotes o
WHERE 
	o.qid = 112794