printmedia
asked on
How to increment by one in SQL table
Hi all.
I have a table (tblRef) that has a column: Ref_No which is a 4 digit number (first one is 1000) as well as other data, I would to be able to make Ref_No 5 digits instead of 4, is there a way to run an update query that will make all of the values in the Ref_No column increment to 5 digits?
Currently, the field is data type: int, what do I have to change it to so I can insert 5 digits instead of 4.
For example,
Currently Ref_No has the following data:
1000
1001
1002
1003
1004
1005
I would like them to be changed to:
10000
10001
10002
10003
10004
10005
etc...
Any ideas? Thanks you in advance!
I have a table (tblRef) that has a column: Ref_No which is a 4 digit number (first one is 1000) as well as other data, I would to be able to make Ref_No 5 digits instead of 4, is there a way to run an update query that will make all of the values in the Ref_No column increment to 5 digits?
Currently, the field is data type: int, what do I have to change it to so I can insert 5 digits instead of 4.
For example,
Currently Ref_No has the following data:
1000
1001
1002
1003
1004
1005
I would like them to be changed to:
10000
10001
10002
10003
10004
10005
etc...
Any ideas? Thanks you in advance!
sorry, my text went missing
try something like
update myTable update key=key - 1000 + 10000
try something like
update myTable update key=key - 1000 + 10000
ok, something is wrong with me today :s
this should be set instead of second update
this should be set instead of second update
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's pretty much it, but what should I change the Data Type to, it is currently int.
>but what should I change the Data Type to, it is currently int.
no need to change, int supports values much larger...
no need to change, int supports values much larger...
int is big enough
The range for an int is from -2^31 to 2^31-1, that is 32-bit signed.
so from -2,147,483,648 to 2,147,483,647
so from -2,147,483,648 to 2,147,483,647
ASKER
Thanks!
Regards,
joachimcarrein