-- http://sqlfiddle.com/#!9/6cc709/1

CREATE FUNCTION `generateGUID`(`playerid` BIGINT UNSIGNED) RETURNS varchar(32) CHARSET latin1
    DETERMINISTIC
BEGIN
 DECLARE temp text CHARSET ascii;
 DECLARE i int;

 SET i = 0;
 SET temp = "";

 WHILE i < 8 DO
    SET temp = CONCAT(temp, CHAR(playerid & 0xFF));
    SET playerid = playerid >> 8;
    SET i = i + 1;
 END WHILE;

RETURN MD5(CONCAT("BE", temp));
END