--SELECT t0.FBILLNO,t0e.FID,t0e.FENTRYID
--FROM T_PUR_POORDER t0
--	INNER JOIN T_PUR_POORDERENTRY t0e on t0e.FID = t0.FID
--	INNER JOIN T_PUR_POORDERENTRY_LK t0e_lk on t0e.FENTRYID = t0e_lk.FENTRYID
--		AND t0e_lk.FSTABLENAME = 'T_SAL_ORDERENTRY'
--	INNER JOIN T_SAL_ORDER t1 on t1.FID = t0e_lk.FSBILLID
--	INNER JOIN T_SAL_ORDERENTRY t1e on t1.FID = t1e.FID AND t0e_lk.FSBILLID = t1e.FID AND t0e_lk.FSID = t1e.FENTRYID

SELECT t0.FBILLNO,t0e.FID,t0e.FENTRYID,t0e.FREALQTY,t1.FBILLNO,t1e.FSTOCKQTY,t2e.FQTY,t2e_lk.FSBILLID,t2e_lk.FSID
FROM T_STK_INSTOCK t0
	INNER JOIN T_STK_INSTOCKENTRY t0e on t0e.FID = t0.FID
	INNER JOIN T_STK_INSTOCKENTRY_LK t0e_lk on t0e.FENTRYID = t0e_lk.FENTRYID
		AND t0e_lk.FSTABLENAME = 'T_PUR_RECEIVEENTRY'
	INNER JOIN T_PUR_RECEIVE t1 on t1.FID = t0e_lk.FSBILLID
	INNER JOIN T_PUR_RECEIVEENTRY t1e on t1.FID = t1e.FID AND t0e_lk.FSBILLID = t1e.FID AND t0e_lk.FSID = t1e.FENTRYID
	INNER JOIN T_PUR_RECEIVEENTRY_LK t1e_lk on t1e.FENTRYID = t1e_lk.FENTRYID
		AND t1e_lk.FSTABLENAME = 'T_PUR_POORDERENTRY'
	INNER JOIN T_PUR_POORDER t2 on t2.FID = t1e_lk.FSBILLID
	INNER JOIN T_PUR_POORDERENTRY t2e on t2.FID = t2e.FID AND t1e_lk.FSBILLID = t2e.FID AND t1e_lk.FSID = t2e.FENTRYID
	INNER JOIN T_PUR_POORDERENTRY_LK t2e_lk on t2e.FENTRYID = t2e_lk.FENTRYID
		AND t2e_lk.FSTABLENAME = 'T_SAL_ORDERENTRY'
	--INNER JOIN T_SAL_ORDER t3 on t3.FID = t2e_lk.FSBILLID
	--INNER JOIN T_SAL_ORDERENTRY t3e on t3.FID = t3e.FID AND t2e_lk.FSBILLID = t3e.FID AND t2e_lk.FSID = t3e.FENTRYID
	--INNER JOIN T_SAL_ORDERENTRY_LK t3e_lk on t3e.FENTRYID = t3e_lk.FENTRYID
	--	AND t3e_lk.FSTABLENAME = 'T_SAL_DELIVERYNOTICEENTRY'
	--INNER JOIN T_SAL_DELIVERYNOTICE t4 on t4.FID = t3e_lk.FSBILLID
	--INNER JOIN T_SAL_DELIVERYNOTICEENTRY t4e on t4.FID = t4e.FID AND t3e_lk.FSBILLID = t4e.FID AND t3e_lk.FSID = t4e.FENTRYID
	--INNER JOIN T_SAL_DELIVERYNOTICEENTRY_LK t4e_lk on t4e.FENTRYID = t4e_lk.FENTRYID
	--	AND t4e_lk.FSTABLENAME = 'T_SAL_OUTSTOCKENTRY'
	--INNER JOIN T_SAL_OUTSTOCK t5 on t5.FID = t4e_lk.FSBILLID
	--INNER JOIN T_SAL_OUTSTOCKENTRY t5e on t5.FID = t5e.FID AND t4e_lk.FSBILLID = t5e.FID AND t4e_lk.FSID = t5e.FENTRYID