I know it's late, but I just want to share what I did for this. I am not allowed to add another table or trigger, so I need to generate it in one query when pasting. In your case, you can try this query.
CREATE TABLE YOURTABLE( IDNUMBER VARCHAR(7) NOT NULL PRIMARY KEY, ENAME VARCHAR(30) not null );
Make a selection and use this selection query and save the @IDNUMBER parameter
(SELECT IFNULL (CONCAT('LHPL',LPAD( (SUBSTRING_INDEX (MAX(`IDNUMBER`), 'LHPL',-1) + 1), 5, '0')), 'LHPL001') AS 'IDNUMBER' FROM YOURTABLE ORDER BY `IDNUMBER` ASC)
And then the Insert query will look like this:
INSERT INTO YOURTABLE(IDNUMBER, ENAME) VALUES (@IDNUMBER, 'EMPLOYEE NAME');
The result will be the same as the other answer, but the difference is that you will not need to create another table or trigger. I hope that I can help someone who has the same case as mine.
yhAm Mar 10 '17 at 2:37 2017-03-10 02:37
source share