DELETE FROM pricing.price_queue;

INSERT INTO pricing.price_queue (bill, ship, part, stlc, v1ds, vol) SELECT 'GRIF0001','GRIF0001','XNS0T1G3G18B096','XNS0T1G3','v1:L..PLT..',9600;

SELECT * FROM pricing.price_queue

EXEC pricing.process_queue


EXEC pricing.single_price_call
    @bill = 'GRIF0001',
    @ship = 'GRIF0001',
    @part = 'XNS0T1G3G18B096',
    @stlc = 'XNS0T1G3',
    @v1ds = 'v1:T..PLT..',
    @vol = 9600;


SELECT 
	price, expl
FROM pricing.single_price_call_fn(
    'GRIF0001',
    'GRIF0001',
    'XNS0T1G3G18B096',
    'XNS0T1G3',
    'v1:B..PLT..',
    12500
) f


SELECT * INTO #result FROM pricing.price_queue WHERE 0=1

INSERT INTO #result
EXEC pricing.single_price_call_nowrite
    @bill = 'GRIF0001',
    @ship = 'JRSG0001',
    @part = 'XNS0T1G3G18B096',
    @stlc = 'XNS0T1G3',
    @v1ds = 'v1:T..PLT..',
    @vol = 19200;

SELECT * FROM #RESULT


SELECT 
	q.qid,
	q.qrn,
	q.qcustomer,
	q.part,
	q.v1ds,
	q.units_each,
	q.price,
	q.targetp,
	q.lastsalesprice,
	q.finalrecommendedprice,
	q.lowerpricelimit,
	q.upperpricelimit,
	q.curstdus,
	p.price guidance,
	p.expl
FROM 
	rlarp.live_quotes q
	OUTER APPLY pricing.single_price_call_fn(
		q.billto
		,q.shipto
		,q.part 
		,substring(q.part,1,8) 
		,q.v1ds 
		,q.units_each
	) p
WHERE
	qstat LIKE 'Submitted%'