Tuesday, 25 October 2011

Remove unused zeros or some other data in front of all Records or from Columns data where the data type is VARCHAR

Example:

create table test ([values] varchar(30))go
insert
into test values ('000001234')insert into test values ('00000000123456')insert into test values ('000123467') insert into test values ('001234787')insert into test values ('00000001234787')insert into test values ('000012343435')go

SELECT
substring([values],PATINDEX('%[^0]%',[values]),10) as [values_modified],'Zeroes is Removed' as Removed_Valuesfrom
test

 

No comments:

Post a Comment