Remove Leading Zeros in a Varchar Column but keep inside spaces



 create table test (col varchar(100))
insert into test values('00876H873 '),('00876 876500'),('0000HUJ8 9IU877 8UJH')

select * ,   LTRIM(Replace(REPLACE(LTRIM(REPLACE(Replace(col, ' ','*'),'0', ' ')), ' ', '0'),'*',' ')) AS NumSerie from test

drop table test

--https://social.msdn.microsoft.com/Forums/en-US/7ece2a11-efac-45b6-97af-af1873788bb0/tsql-remove-leading-zeroes-in-a-string?forum=transactsql

 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s