SELECT S.STOKID, S.KODU, S.ADI, SUM(ADET*TUR) AS TKG FROM (SELECT STOKID,KODU,ADI,BIRIM,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,ADI,SALISFIYAT,SFIYAT1,ALISKDV,SATISKDV,SALISFIYAT*(100.00-SATISIND)/100.00 AS SFIYAT FROM STOK WHERE SATISIND>0 UNION ALL SELECT STOKID,KODU,ADI,BIRIM,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,ADI,SALISFIYAT,SFIYAT1,ALISKDV,SATISKDV,SALISFIYAT*(100.00+SKARY)/100.00 AS SFIYAT FROM STOK WHERE SKARY>0) AS S , FATISL, FATURA WHERE FATURA.FATID=FATISL.FATID AND S.STOKID=FATISL.STOKID GROUP BY S.STOKID, S.KODU, S.ADI