How to use padding in MySQL

Last Reply one year ago By dharmendr

Posted one year ago

dear sir this my blow mysql stored procedure for generate Ticket in sequence like example

#ticket00001

in this stored procedure i am getting result 

this #ticket2 insted of #ticket00002

i need my next result should be proper 

 

CREATE DEFINER=`root`@`localhost` PROCEDURE `spGenerateTicket`()
BEGIN
       declare fixname varchar(10);
       declare oldTicket varchar(15);
       declare numId int ;
       declare newTicket varchar(45);
      -- declare newIntId int ;
       
       if exists (select TicketNo from tbl_ticketmaster order by TicketNo desc limit 1) then 
       begin 
	   set fixname = '#ticket';
       set oldTicket = (select TicketNo from tbl_ticketmaster order by TicketNo desc limit 1);
       
	  --  set numId = (select oldTicket , SUBSTRING_INDEX(oldTicket,'t',-1));
     -- set numId = (select SUBSTRING_INDEX(oldTicket,'t',-1) as numPart);
        set numId = (select SUBSTRING_INDEX(oldTicket,'t',-1) as numPart);
       set newTicket = (select concat(fixname,'',numId+1));
	   select newTicket;
       
      end ;
       
       else
       insert into TicketNo values (null , '#ticket0001');
       
       end if;
       
END

 

You are viewing reply posted by: dharmendr one year ago.
Posted one year ago

You can't ask multiple queries within a question. This is against forum rules and necessary to maintain clean forum.
It is requested Mark Answer the replies when question is answered and ask a new question as a responsible member to help fellow programmers around the world.
Note: If you don't mark answers, people will loose interest in your questions.

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html