Using the following very useful document

http://dev.mysql.com/tech-resources/...procedures.pdf I managed to rewrite MS SQL function.

Working copy:

DELIMiTER //

drop PROCEDURE IF EXISTS getRoadFundLicense;//

CREATE PROCEDURE getRoadFundLicense

(

IN fueltype char(1),

IN co2 int,

IN months int,

OUT result double

)

BEGIN

set result = 0;

if months=12 then

-- band A

if co2 >= 0 and co2 <=100 then

set result = 0;

elseif co2 >= 101 and co2 <=120 then

-- band B

if fueltype = 'D' then set result = 50;

elseif fueltype = 'P' then set result = 40;

else set result = 30;

end if;

elseif co2 >= 121 and co2 <=150 then

-- band C

if fueltype = 'D' then set result = 110;

elseif fueltype = 'P' then set result = 100;

else set result = 90;

end if;

elseif co2 >= 151 and co2 <=165 then

-- band D

if fueltype = 'D' then set result = 135;

elseif fueltype = 'P' then set result = 125;

else set result = 115;

end if;

elseif co2 >= 166 and co2 <=185 then

-- band E

if fueltype = 'D' then set result = 160;

elseif fueltype = 'P' then set result = 150;

else set result = 140;

end if;

elseif co2 >= 186 and co2 <= 225 then

-- band F

if fueltype = 'D' then set result = 195;

elseif fueltype = 'P' then set result = 190;

else set result = 180;

end if;

elseif co2 >= 226 then

-- band G

if fueltype = 'D' then set result = 215;

elseif fueltype = 'P' then set result = 210;

else set result = 200;

end if;

end if;

elseif months=6 then

-- band A

if co2 >= 0 and co2 <=100 then

set result = 0;

elseif co2 >= 101 and co2 <=120 then

-- band B

if fueltype = 'D' then set result = 0;

elseif fueltype = 'P' then set result = 0;

else set result = 30;

end if;

elseif co2 >= 121 and co2 <=150 then

-- band C

if fueltype = 'D' then set result = 60.50;

elseif fueltype = 'P' then set result = 55;

else set result = 49.50;

end if;

elseif co2 >= 151 and co2 <=165 then

-- band D

if fueltype = 'D' then set result = 74.25;

elseif fueltype = 'P' then set result = 68.75;

else set result = 63.25;

end if;

elseif co2 >= 166 and co2 <=185 then

-- band E

if fueltype = 'D' then set result = 88;

elseif fueltype = 'P' then set result = 82.50;

else set result = 77.00;

end if;

elseif co2 >= 186 and co2 <= 225 then

-- band F

if fueltype = 'D' then set result = 107.25;

elseif fueltype = 'P' then set result = 104.50;

else set result = 99;

end if;

elseif co2 >= 226 then

-- band G

if fueltype = 'D' then set result = 99;

elseif fueltype = 'P' then set result = 115.50;

else set result = 110;

end if;

end if;

end if;

END;//

DELIMITER ;//

Use the following to return result:

call getRoadFundLicense('P',228,6,@result);

select @result;