SELECT SUM
       ( asrsQty ) asrsQty,
       SUM ( erpQty ) erpQty,
       matnr,
       specs,
       maktx
FROM
    (
        SELECT CAST
               ( SUM ( qty ) AS INT ) asrsQty,
               0 AS erpQty,
               matnr,
               specs,
               maktx
        FROM
            asr_loc_detl
        GROUP BY
            matnr,
            specs,
            maktx UNION ALL
        SELECT
            0,
            CAST ( SUM ( numis ) AS INT ),
            itemid,
            itemcode,
            itemname
        FROM
            (
                SELECT
                    *
                FROM
                    OPENROWSET ( 'SQLOLEDB', '192.168.1.147,1800'; 'XGMLK'; 'xunda0413', XDLinkLK.dbo.vwErpLKStorage )
		WHERE
			LKName = '中扬' 
		) a 
	GROUP BY
		itemid,
		itemcode,
		itemname 
	) b WHERE 1=1 and matnr not in (select matnr from man_order_detl)
GROUP BY
	matnr,
	specs,
	maktx