Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ltrim( )

Status
Not open for further replies.

atiqraza

Programmer
Jan 9, 2007
24
US
hello everybody
I have a table with one colum in which i need to get rid of the leading 0's. It would have been easier to just change the datatype to int. However i can not since some columns have some characters in them.

LTRIM() only seems to get rid of leading blanks..Anybody know a function on how to get rid of Leading zeros.
i.e

00089 gets changed to 89.

Thanks
 
Take a look at this...


Code:
Declare @Temp Table(Data VarChar(20))

Insert into @Temp Values('0000089')
Insert into @Temp Values('24')
Insert into @Temp Values('Eight')
Insert into @Temp Values('00000A')

Select 'Before', Data From @Temp

Update @Temp
Set    Data = Case When IsNumeric(Data + 'e0') = 1
                   Then Convert(VarChar(20), Convert(Int, Data))
                   Else Data
                   End


Select 'After', Data From @Temp

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
yan,

e0 is explained in this Faq: faq183-6423



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top