Вместо бекапа

Sep 26, 2009 03:35

Сама функция, надеюсь вспомнил её правильно, под катом.


CREATE FUNCTION `oTotalPrice`(oid INT(8), curr INT(8)) RETURNS INT(11)
BEGIN
DECLARE res INT(16);
SELECT parent INTO res FROM orders WHERE id=oid LIMIT 1;
IF res IS NOT NULL THEN RETURN 0; END IF;
SELECT
SUM(
IF (orders.customPriceCurr,
ConvertCurrency(orders.customPriceCurr,curr,parent_orders.period/orders.period*orders.customPrice),
ConvertCurrency(services_price.currency,curr,parent_orders.period/orders.period*services_price.price)
)
) INTO res
FROM
orders AS parent_orders,orders,services_price
WHERE
(orders.id=oid OR orders.parent=oid) AND
parent_orders.id=oid AND
orders.service_id = services_price.service_id AND
orders.period = services_price.period;
IF res IS NULL THEN SET res = 0; END IF;
RETURN res;
END$$

sql

Previous post Next post
Up