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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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)
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))
d27m11yAuthor Commented:
sorry not delete, display  '000001020304043575' as 1020304043575
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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)
awking00Information Technology SpecialistCommented:
select right(field, len(field) - 5)
where field like '00000%'

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
awking00Information Technology SpecialistCommented:
If you want it to be a number rather than a string, you can certainly cast it.
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.
awking00Information Technology SpecialistCommented:
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.
d27m11yAuthor Commented:
How can I use cast to display removing leading zeros, please help !
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.
d27m11yAuthor Commented:
I think I can use cast(cast(AccountNumber as bigint) as varchar)
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.
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))
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.