şu kod belki fikir verebilir:
SELECT
M.CODE
,M.NAME
,T.ONHAND
,BİRİM_L.CODE AS 'ANA_BİRİM'
,(SELECT TOP 1 (TOTAL-DISTCOST)/(AMOUNT)/UINFO2
FROM LG_216_01_STLINE S
WHERE STOCKREF=M.LOGICALREF
AND (TRCODE=1 OR (TRCODE=14 AND BILLED=0) )
AND LPRODSTAT=0 AND LINETYPE=0
ORDER BY DATE_ DESC) AS SON_ALIŞ
,(SELECT MAX(PRICE) FROM LG_216_PRCLIST P WHERE P.CARDREF=M.LOGICALREF) AS TANIMLI_ALIŞ
FROM
LG_216_ITEMS M
INNER JOIN LV_216_01_GNTOTST T ON T.STOCKREF=M.LOGICALREF
INNER JOIN LG_216_UNITSETF BİRİM_F ON M.UNITSETREF=BİRİM_F.LOGICALREF
INNER JOIN LG_216_UNITSETL BİRİM_L ON BİRİM_L.UNITSETREF=BİRİM_F.LOGICALREF
WHERE INVENNO=-1 AND ONHAND<>0