Skip to content

Instantly share code, notes, and snippets.

@farindra
Created June 24, 2015 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farindra/2438679784138153bb49 to your computer and use it in GitHub Desktop.
Save farindra/2438679784138153bb49 to your computer and use it in GitHub Desktop.
begin
DECLARE id_old,id_new INT(11);
DECLARE id_var varchar(20);
SELECT ifnull(right(MAX(kd_berita),4),'0000') into id_var from a1000 where month(CURDATE())=month(created_at);
set id_old=cast( id_var as unsigned);
set id_new= id_old+1;
SET id_var = '';
SET id_old = 1;
label1: LOOP
IF id_old <= (4-length(cast(id_new as char(10)))) THEN
SET id_var = concat( id_var,'0');
SET id_old = id_old+1;
ITERATE label1;
END IF;
LEAVE label1;
END LOOP label1;
set id_var=concat(id_var,id_new);
set NEW.kd_berita=concat(replace(CURDATE(),'-',''),'.BA.', id_var);
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment