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
After run the above query you will get the output: 123050
Remember that the orginal string was: 000123050
No comments