Brightlane's data pipeline strips leading zeros from account numbers before loading them into a reporting system.
Write a query to return the value of '000042' after every leading '0' character is removed.
Output:
- A single row with one column,
account_number, containing the stripped value.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
TRIM(
LEADING '0'
FROM
'000042'
) AS account_number The shape
TRIM(LEADING '0' FROM '000042') walks the left side of the string and removes every '0' character it encounters until it hits a non-'0', at which point it stops. The four leading zeros are stripped and the result is the string '42', which is the form the reporting system loads.
Clause by clause
SELECT TRIM(LEADING '0' FROM '000042') AS account_numberruns the directionalTRIMagainst the literal and labels the resultaccount_number. TheLEADINGkeyword tellsTRIMto operate only on the left end of the string; the'0'is the character to strip. Each leading'0'is removed one by one until the function reaches the'4', which is not a'0', so the function stops and returns what remains.- There is no
FROMbecause the value being stripped is the literal in theSELECT. The function takes one input and returns one output.
Why this and not the default both-sides TRIM
A plain TRIM('0' FROM '000042') would strip from both ends, and since the string ends in '2' rather than '0', the right-side pass would do nothing on this specific input and the result would be the same '42'. The LEADING keyword is still load-bearing for the pipeline. An account number like '01020' would lose its trailing '0' under a both-sides strip, which would silently corrupt the value. LEADING makes the directional intent explicit and keeps the behavior correct for every input the pipeline will see.
You practiced TRIM(LEADING 'char' FROM ...) — strip a specific character only from the left side, preserving the right side intact.