JSFiddle - React, Tailwind, and code Playground
JavaScript
set @sequence = 'CUST_';
set @custval = (select max(VSCST_CUSTNO) from vs_customer);
IF(@custval IS NULL) THEN
set @custval = '01000';
ELSE
set @custval = SUBSTR(@custval,6,5);
END IF;
set @i = cast(@custval AS SIGNED) + 1;
set @NewOrder = (select concat(@sequence, right(concat('0000', cast(@i as SIGNED)),5)));
select @NewOrder;