Remove leading zeroes from varchar

The following example shows one way how you can remove leading zeroes from a varchar column in SQL Server:

declare @MyVal varchar(20);
set @MyVal = '0001234ABC00';
select @MyVal, replace(ltrim(replace(@MyVal, '0', ' ')), ' ', '0')

Returns:

'0001234ABC00', '1234ABC00'

Leave a Reply

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

*