Search code examples
sqlgoogle-bigquerysubstring

How to Remove Leading "0" in a string in BigQuery?


I am looking to remove the leading zeros in a string.

Below are my current results:

Department
026P-PLUMBING
0021-LUMBER
029B-KITCHEN AND BATH
025H-HARDWARE (25H)
0022-BUILDING MATERIALS

Below are my Desired Results:

Department
26P-PLUMBING
21-LUMBER
29B-KITCHEN AND BATH
25H-HARDWARE (25H)
22-BUILDING MATERIALS

Solution

  • Use LTRIM(Department, '0') as in below example

    select trim(Department, '0')
    from your_table           
    

    if applied to sample data in your question - output is

    enter image description here