How to add an integer value to increment a varchar

I have a table (Table1) that has a varchar(5) as it's PK (Table1ID)
I need to do a mass update to Table1ID and add 1000 to each record as if the field was an integer. I need to retain the leading zero for thoses records less than 10000. I'm thinking a cast or convert is needed but not sure how to proceed.

Here is what I tried but just got a concatenation of the values, but it is the idea of what I need.
UPDATE Table1
SET Table1ID = Table1ID + '1000'
WHERE Table1ID BETWEEN '01000' AND '01410'

LVL 6
AkAlanAsked:
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.

TempDBACommented:
I can't figure out clearly what you want to do. But if you want to know how to add the cast\convert into the query you provided, it can be done as:-

UPDATE Table1
SET Table1ID = cast((cast(Table1ID as int) + 1000 ) as varchar)
WHERE Table1ID BETWEEN '01000' AND '01410'

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
Jesus RodriguezIT ManagerCommented:
use th cast or convert function in SQL for it. if TableID is varchar then try SOMETHING LIKE THIS

UPDATE TABLE1
SET TABLE1ID=CONVERT(VARCHAR,CAST(TABLE1ID AS INT)+1000)
WHERE CAST(TABLE1ID AS INTEGER) BETWEEN 1000 AND 1410
0
AkAlanAuthor Commented:
Both solutions were good, and timely. I did have to alter them to get the desired results and that was that I keep the leading zero like this. Thanks for the help

UPDATE TABLE1
SET TABLE1ID= '0' + CONVERT(VARCHAR,CAST(TABLE1ID AS INT)+1000)
WHERE CAST(TABLE1ID AS INTEGER) BETWEEN 1000 AND 1410
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 2008

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.