LPAD pads the beginning of a string with a specified character or sequence until the requested length is reached.
Standard-length identifiers are often required for reporting, file exports, and system integrations.
Add leading zeros to an employee ID.
SELECT
EmployeeID,
LPAD(CAST(EmployeeID AS VARCHAR), 6, '0') AS FormattedEmployeeID
FROM Employees;
LPAD is useful for formatting account numbers, employee IDs, product codes, and fixed-width export fields.
- LPAD adds characters to the beginning.
- A target length is specified.
- It is useful for fixed-length identifiers.
- Leading zeros are a common use case.
- Function availability varies by database.
What does LPAD do?
LPAD adds specified characters to the beginning of a string until it reaches a target length.
Why use LPAD with employee IDs?
LPAD can create consistently formatted identifiers such as 000123 or 001245.