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 2005 Forums
 Transact-SQL (2005)
 Extra 0 in column to be removed

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-11-29 : 10:15:15
Hi i've a column which is getting a extra 0 at the start of it is there a way to remove this extra 0,

I know its the first 0 but i do not know the full lenght of the digit that in the column.

Example
Col1
01000
02000
00322
00122

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-29 : 10:35:40
select substring( columnName, 2, len(columnName))
or
select RIGHT ( columnName, len(columnName) - 1 )



_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-29 : 10:39:03
select substring(col1,2,len(col1)) as Col1
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-29 : 10:42:15
Damn, I go away and do some work and then get snipped.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-29 : 10:47:00


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-30 : 01:49:40
quote:
Originally posted by rookie_sql

Hi i've a column which is getting a extra 0 at the start of it is there a way to remove this extra 0,

I know its the first 0 but i do not know the full lenght of the digit that in the column.

Example
Col1
01000
02000
00322
00122


If you meant to remove leading zeroes then

select cast(col as int) from table

provided col has no non-numeric characters

Madhivanan

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

- Advertisement -