I need your help. I should create a function which calculates the prescription costs of a prescription. The formula should be like this:
price of medicine x dosage x ceiling(duartion/24h)
The signature of function is:
prescription costs(mname varchar(100), dosage int, duration time)
DELIMITER $$
CREATE FUNCTION prescription_costs (mname varchar(100), dosage int, duration time) RETURNS INT
BEGIN
DECLARE prescription_costs INT;
IF mname < 0 THEN
SET prescription_costs = 0;
ELSEIF dosage < 0 THEN
SET prescription_costs = 0;
ELSEIF duration < 0 THEN
SET prescription_costs = 0;
ELSE
SET prescription_costs = price*dosage*ceiling(duration/24);
END IF;
RETURN (prescription_costs);
END;
$$
DELIMITER ;
So, after running I will get this window:
Instead of usage of the price from the medicine I have to use the name of the medicine which refers to its price in the table.
The table prescription is:
That means, if I put in the name of the medicine, the price should be taken for the calculation but I dont know how to.
I suppose I have to combine select statement in the create function statement.
BTW: English is not my native language!!! Please forgive me for mistakes!