Jak napisać funkcję mysql z dynamiczną nazwą tabeli?

Próbuję napisać moją funkcję sql, wykonując następujące czynności: 1- uzyskać nazwę tabeli użytą w join jako parametr.

ale otrzymuję błąd składni mysql

1064 - You have an error in your SQL syntax; check the manual that corresponds to 
  your MySQL server version for the right syntax to use near 'table DETERMINISTIC 
  BEGIN select `r`.`id` AS `id`, (case ' at line 2

To jest moje zapytanie

DELIMITER $
CREATE FUNCTION getTranslation (tablename varchar(50),entity varchar(20),itemid int,lang char(3)) 
RETURNS table
DETERMINISTIC
BEGIN 
select 
    `r`.`id` AS `id`,
    (case
        when isnull(`t`.`descr`) then `r`.`descr_ml`
        else `t`.`descr`
    end) AS `descr`
from
    (tablename `r`
    left join `g001_translation` `t` ON ((`t`.`item_id` = `r`.`id`)))
END$
DELIMITER ;

I tak wybrana część działa dobrze ze statyczną nazwą tabeli.

questionAnswers(2)

yourAnswerToTheQuestion