#1415 - Not allowed to return a result set from a function
DELIMITER $$
CREATE FUNCTION Test.FnGetLastDayLastFinYear (pdate datetime)
RETURNS DATETIME
BEGIN
Declare MonthNo int;
Declare YearNo int;
DECLARE OUTPUTDATE DATETIME;
SELECT MonthNo = DATEPART(MONTH,@pdate);
if(@MonthNo <= 3)
then
SELECT @YearNo = (DatePart(Year,getdate()) - 1);
Select @OUTPUTDATE = Date_Format(@YearNo,'%d/%m/%Y');
ELSE
Select @OUTPUTDATE= Date_Format(@pdate,'%d/%m/%Y');
END If;
RETURN @OUTPUTDATE;
END