delete first five zeroes in an accountnumber in sql server

I have an accountnumber, say 000001020304043575.. I would like to delete only first 5 zeroes in Sql server. Please advise
d27m11yAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Deepak ChauhanSQL Server DBACommented:
select right('000001020304043575',len('000001020304043575')-5)
0
Brian CroweDatabase AdministratorCommented:
Just in case it's not always 5 zeroes and you just want to remove leading zeroes...

DECLARE @AcctNumber      VARCHAR(50) = '000001020304043575'

SELECT SUBSTRING(@AcctNumber, PATINDEX('%[^0]%', @AcctNumber), LEN(@AcctNumber))
0
d27m11yAuthor Commented:
sorry not delete, display  '000001020304043575' as 1020304043575
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Deepak ChauhanSQL Server DBACommented:
If you want to delete this value from table, you have to update the table.  But first test this in test table before implement on production table.

update tablename
set colname =right(AccountNOColumn,len(accountNoColumn)-5)
0
awking00Commented:
select right(field, len(field) - 5)
where field like '00000%'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
d27m11yAuthor Commented:
Can I use cast
0
awking00Commented:
If you want it to be a number rather than a string, you can certainly cast it.
0
d27m11yAuthor Commented:
Actually, I just realized the whole size of the accountnumber is varchar(25). However, the accountnumber can be 16 digits or 17 digits and rest are leading zeros. How do I trim leading zeros in this case.
0
awking00Commented:
Brian Crowe already showed you how to do that by taking the substring starting at the first non-zero character, which could then be cast to numeric.
0
d27m11yAuthor Commented:
How can I use cast to display removing leading zeros, please help !
0
Brian CroweDatabase AdministratorCommented:
You've already gotten that answer.  You haven't provided a query or any schema information so you got a generic usage.
0
d27m11yAuthor Commented:
I think I can use cast(cast(AccountNumber as bigint) as varchar)
0
Brian CroweDatabase AdministratorCommented:
That could work depending on the size of the account number.  You would have to test to see if it is the most performant.
0
Scott PletcherSenior DBACommented:
I'd offer one very slight mod to Brian's response, just on the off chance that the whole acct number is zero.  Naturally NO points for me please:

SELECT SUBSTRING(@AcctNumber, PATINDEX('%[^0]%', @AcctNumber + ' '), LEN(@AcctNumber))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

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.