473,471 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Updating a series with a single query

hi:

I've a series of records, say 1000, have a counter field which is
indexed+no duplicates.
I want to set counter to (counter+1), when I execute this query, it
takes error because of duplicate values, what should I do?

UPDATE Table1 SET id=id+1;

thanks n regards
Nov 12 '05 #1
6 1367
Abdolhosein Vakilzadeh Ebrahimi wrote:
hi:

I've a series of records, say 1000, have a counter field which is
indexed+no duplicates.
I want to set counter to (counter+1), when I execute this query, it
takes error because of duplicate values, what should I do?

UPDATE Table1 SET id=id+1;

thanks n regards


Convert it to a long int.
Nov 12 '05 #2
This code is untested and if you're using an autonumber field, I'm not sure
if you can update that.
Basically you need to increment your ids starting with the record with the
highest id number.

dim db as database
dim rst as recordset

set db = currentdb()
set rst = db.openrecordset("select * from Table1 order by id desc")

while not rst.eof
rst.edit
rst.fields("id") = rst.fields("id") + 1
rst.update
rst.movenext
wend

rst.close
db.close

"Abdolhosein Vakilzadeh Ebrahimi" <va********@kzlabs.com> wrote in message
news:b9**************************@posting.google.c om...
hi:

I've a series of records, say 1000, have a counter field which is
indexed+no duplicates.
I want to set counter to (counter+1), when I execute this query, it
takes error because of duplicate values, what should I do?

UPDATE Table1 SET id=id+1;

thanks n regards

Nov 12 '05 #3
"Abdolhosein Vakilzadeh Ebrahimi" <va********@kzlabs.com> wrote in message
news:b9**************************@posting.google.c om...
hi:

I've a series of records, say 1000, have a counter field which is
indexed+no duplicates.
I want to set counter to (counter+1), when I execute this query, it
takes error because of duplicate values, what should I do?

UPDATE Table1 SET id=id+1;


Try first setting the ID to a range that will guarantee no duplicates (add
100000 for example) then run a second query that subtracts 99999 from the ID
value.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 12 '05 #4
va********@kzlabs.com (Abdolhosein Vakilzadeh Ebrahimi) wrote in
news:b9**************************@posting.google.c om:
hi:

I've a series of records, say 1000, have a counter field which
is indexed+no duplicates.
I want to set counter to (counter+1), when I execute this
query, it takes error because of duplicate values, what should
I do?

UPDATE Table1 SET id=id+1;

thanks n regards


You are creating a duplicate record 2 when counter is 1, so you
have to renumber 2 before you renumber record 1.

Run the query on the series sorted in descending order.
Then record 2 has already been renumbered to 3 and you dont get the
error.

Bob Q
Nov 12 '05 #5
you need to process the row with the largest ID first,

create a query (qryTable1) that returns the rows in desc ID order
SELECT id FROM table1 ORDER BY id DESC;

then base your update on this query
UPDATE qryTable1 SET id=id+1;
va********@kzlabs.com (Abdolhosein Vakilzadeh Ebrahimi) wrote in message news:<b9**************************@posting.google. com>...
hi:

I've a series of records, say 1000, have a counter field which is
indexed+no duplicates.
I want to set counter to (counter+1), when I execute this query, it
takes error because of duplicate values, what should I do?

UPDATE Table1 SET id=id+1;

thanks n regards

Nov 12 '05 #6
HIGH!

THANKS. It worked.
Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aW | last post by:
I have an interesting dilemma. I have a table with the following records: =================================================== Box | Series Start | Series End...
3
by: Chuck Reed | last post by:
I am working on a sales report where I show weekly sales by category for each of the 52 weeks in the year. Each record in my table/report has the 52 weeks of sales in it. I want to highlight to top...
2
by: Ray Holtz | last post by:
I have a form that shows a single record based on a query criteria. When I click a button it is set to use an append query to copy that record to a separate table, then deletes the record from the...
1
by: teddyparnell | last post by:
I have a query that works, but then displays the results in a datasheet view. The query is reliant on the results of a combo box, and when i update this combo box and click a button the results of...
1
by: civa | last post by:
Hii, I have created a check writing program which consists of a table name "DATA" with fields CHECKNO, CHECKDT, BANKNAME & AMOUNT & also a query with date criteria with the above fields. I have 2...
6
by: Mike Wilson | last post by:
Dear Group, I have a heirarchical set of database tables, say - "order" and "order_type" and want to display a series of orders in a grid control, and in place of the order_type foreign key...
14
by: John T Ingato | last post by:
I have a contacts table with name address and such but are missing all phone numbers in the phone number fields. I have just received an updated customer list in Excel and have imported into a new...
1
by: davidevan | last post by:
What I'm trying to do is set a players division according to their age. So if age is 8, update division to junior, if age is 9, update division to medium, if age is 10, update division to pee wee,...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.