SELECT SUM(ISNULL((a.Price * x.Factor) - Discount /100,(b.Price * x.Factor) - Discount / 100))) FROM TABLEA a, TABLEB b, TABLEX x