Skip to content
Advertisement

Remaining leading zero after adding in sql

When employee_id is added by one, leading zeros are removed in the following query.

SELECT SUBSTRING(MAX(ID), 6, 4)+1 FROM `employee`

Here is my table.

How can I remain leading zeros?

Advertisement

Answer

Option 1:

You can use LPAD. here is the demo. this will keep your ID length of 4.

Option 2: You can use concat and here is the demo.

Output:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement