Tuesday, 2 October 2007

Remove leading and trailing zeros from a numeric string

declare @str nvarchar(10)

set @str = '00101abc2300'

select replace(ltrim(rtrim(replace(@str, '0', ' '))), ' ', '0')

1 comment:

aslam said...

to remove only 'O' from left side only use:

select replace(ltrim(replace(@str, '0', ' ')), ' ', '0')