This MySQL syntax (function) is error. I had checked it, but I can't repaired. How I can repair it? : CREATE FUNCTION FC_IDKRITERIA()
RETURNS CHAR(3)
AS
BEGIN
DECLARE @MAX INT , @KODEBARU CHAR(3)  
SELECT @MAX = MAX (RIGHT(IDKRITERIA,2)) FROM KRITERIA
IF @MAX IS NULL 
SET @MAX = 0
SET @KODEBARU = 'K' + RIGHT('0'+CONVERT(VARCHAR(3),@MAX+ 1 ) ,2)
RETURN @KODEBARU
END