September 29, 2020
sql-database

Remove or trim the leading zeros in SQL

Some times we need to remove or trim the leading zeros in an alphanumeric column of a table flied. Following SQL query will help us to  do this.

DECLARE @String nvarchar(100)

SET @String='000123050'

SELECT SUBSTRING(@String,PATINDEX('%[1-9]%', @String),LEN(@String))

Output
After run the above query you will get the output: 123050
Remember that the orginal string was: 000123050

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

One thought on “Remove or trim the leading zeros in SQL

Leave a Reply

Your email address will not be published. Required fields are marked *