SELECT SUM
	( asrsQty ) asrsQty,
	SUM ( erpQty ) erpQty,
	matnr,
	maktx,
	MIN ( pgNo ) pgNo,
	MIN ( outOrderNo ) outOrderNo,
	MIN ( batch ) batch,
	model,
	MIN ( specs ) specs
FROM
	(
	SELECT CAST
		( SUM ( anfme ) AS INT ) asrsQty,
		0 AS erpQty,	matnr,
		model,

		maktx,
		pg_no AS pgNo,
		out_order_no AS outOrderNo,
		batch,
		specs
	FROM
		asr_loc_detl
	GROUP BY
		matnr,
		maktx,
		pg_no,
		out_order_no,
		batch,
		model,
		specs UNION ALL
	SELECT
		0,
		CAST ( SUM ( numis ) AS INT ),
		itemid,
		itemcode,
		itemname,
		'' AS pgNo,
		'' AS outOrderNo,
		itembatch AS batch,
		itemSpc specs
	FROM
		( SELECT * FROM OPENROWSET ( 'SQLOLEDB', '192.168.1.147,1800'; 'XGMLK'; 'xunda0413', XDLinkLK.dbo.vwErpLKStorage ) WHERE LKName = '高霖立库' ) a
	GROUP BY
		itemid,
		itemcode,
		itemname,
		itembatch,
		itemSpc
	) b
WHERE
	1 = 1
	AND matnr NOT IN ( SELECT matnr FROM man_order_detl )
GROUP BY
	matnr,
	model,
	maktx