Tuesday, March 20, 2012

Removing Zeros

Hi,
I have a column cost with sample record as '00003433' . how can i remove all zeros in left side alone?.

Out put : 3433.

Thanks
Raj

You can just convert the value to INT.

e.g.

Code Snippet

select convert(int,'00003433')

|||

Try this..

Select replace(Columnname, '0','')

From table

*** Place your tablename and column name in the query..

|||

Hi,

Oj is correct, use convert function to removes all zeros in left side of your column data, but when you use "repalce" function it'll removes all zeros, not only in left side.

for eg:

declare @.a varchar(8)
set @.a = '00003405'

select convert(int,@.a) ,replace(@.a, '0','')

Thanks & Regards,

Kiran.Y

No comments:

Post a Comment