If you are dealing with strings as nvarchar and varchar in SQL Server what is the correct way to drop leading zeros without casting to an INT type?
Say '000123' for example. I would like to convert this into '123'
If you are dealing with strings as nvarchar and varchar in SQL Server what is the correct way to drop leading zeros without casting to an INT type?
Say '000123' for example. I would like to convert this into '123'
DECLARE @Var VARCHAR(100) = '000000658410065446'
SELECT SUBSTRING(@Var, PATINDEX('%[^0]%',@Var), 100)
OR
SELECT SUBSTRING(@Var, PATINDEX('%[^0]%',@Var),
LEN(@Var)- PATINDEX('%[^0]%',@Var)+ 1)
Both will return the same Result as follows
Result
658410065446