Solved

How to increment an integer with SQL?

Posted on 2008-10-03
2
227 Views
Last Modified: 2013-12-19
How can I increment an integer which is stored in the database as for example "00006".

When I tried to update and did:

set amount = amount + 1

the update was as 7 instead of 00007.

Can you help please?

thanks.

0
Comment
Question by:Rassac
  • 2
2 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22634547
this should do:

set amount = right( '00000' + cast(cast(amount as int) + 1  as varchar(10)), 6)

Open in new window

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 22634552
sorry, that was mssql :(
TO_CHAR( amount + 1, '000000')

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
capture vmstat info and insert it into an oracle table 31 39
SQL trigger 5 25
Using SQL*PLUS issue with where statement with trunc function 3 29
sql server query 12 26
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question