Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 removing leading zeros using trim

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-12-22 : 07:49:32
balaji writes "i have a column called fileno consists of values with leading zeros like '022545','0003235','004566'.....how to remove those leading zeros from the column

kindly revert me with the answer"

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-22 : 07:54:48
select fileno, cast(fileno as bigint), cast(fileno as int)
from <YourTableNameHere>


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-22 : 08:36:46

1 If those strings are only numbers, above suggestion will work
2 If you have data like '0000123HL98', that wont work

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-12-22 : 09:39:04
As long as you don't have any embedded (non-leading/non-trailing) spaces, this will work too:

SELECT Replace(Ltrim(Replace(fileno, '0', ' ')), ' ', '0') FROM myTable
Go to Top of Page
   

- Advertisement -