how to remove '0' from left of the column in sql server 2005

colum type is varchar and want to remove '0' only from left.
sample data
000007
000008
000009
000010

output should be
7
8
9
10



easy_lifeAsked:
Who is Participating?
 
Kevin CrossConnect With a Mentor Chief Technology OfficerCommented:
One easy way if these are numbers is to:

CAST(columnname AS INT)

You may want BIGINT depending on the scale of the field, but hopefully you get the idea.
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT CAST (urColumn as INT)  newname
from urTable
0
 
justin-clarkeCommented:
SELECT (CAST Col1 AS int) AS Col1

Then converts it to an INT therefore removing the leading zeros
0
 
Scott PletcherSenior DBACommented:
SELECT SUBSTRING(columnName, PATINDEX('%[^0]%', columnName), DATALENGTH(columnName))


For example:

SELECT SUBSTRING(columnName, PATINDEX('%[^0]%', columnName), DATALENGTH(columnName))
FROM (
    select '000007' as columnname union all select
'000008' union all select
'000009' union all select
'000010' union all select
'00010010'
) as testdata
0
 
easy_lifeAuthor Commented:
Thanks for your quick response
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.