473,385 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help With SQL Update With Duplicate Records

Hi Gang

I have a simple table with some duplicate values.

Field1 Field2 Field3
Andy Smith 10
Andy Smith 10
Andy Smith 10

With an SQL Update statement, how would I change the table to look like

this. I need to increment Field3 by 10 for each record.

Field1 Field2 Field3
Andy Smith 10
Andy Smith 20
Andy Smith 30

Please help.
Andy

Mar 17 '06 #1
3 4413
On 17 Mar 2006 11:20:34 -0800, "Andy" <an***********@siemens.com>
wrote:

That's really hard to do with a sql update statement. Rather process
the table using a recordset.

-Tom.

Hi Gang

I have a simple table with some duplicate values.

Field1 Field2 Field3
Andy Smith 10
Andy Smith 10
Andy Smith 10

With an SQL Update statement, how would I change the table to look like

this. I need to increment Field3 by 10 for each record.

Field1 Field2 Field3
Andy Smith 10
Andy Smith 20
Andy Smith 30

Please help.
Andy


Mar 18 '06 #2
Tom

How would I do this with a record set? Would I load all the records
into a recordset, do my data manipulation, delete all the records in
the table and then write the records in the recordset back to the empty
table?

Please help.

Andy

Mar 20 '06 #3
On 20 Mar 2006 10:15:04 -0800, "Andy" <an***********@siemens.com>
wrote:

You wanted to go from:
Field1 Field2 Field3
Andy Smith 10
Andy Smith 10
Andy Smith 10
Jim Jones 10
Jim Jones 10
to:Field1 Field2 Field3
Andy Smith 10
Andy Smith 20
Andy Smith 30
Jim Jones 10
Jim Jones 20
'aircode:
dim db as dao.database
dim rs as dao.recordset
dim strField1 as string
dim strField2 as string
dim lngField3 as long
set db=currentdb()
set rs=db.openrecordset("select * from MyTable order by Field1,
Field2, Field3", dbOpenDynaset)
while not rs.eof
if rs!Field1=strField1 and rs!Field2=strField2 then
'still on same firstname/lastname: increment by 10
rs.edit
lngField3=lngField3+10
rs!Field3=lngField3
rs.update
else
'new firstname/lastname: initialize variables
strField1=rs!Field1
strField2=rs!Field2
lngField3=0
end if

rs.movenext
wend
rs.close

-Tom.
Tom

How would I do this with a record set? Would I load all the records
into a recordset, do my data manipulation, delete all the records in
the table and then write the records in the recordset back to the empty
table?

Please help.

Andy


Mar 21 '06 #4

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

Similar topics

6
by: a-ok | last post by:
Hi, My client has a product database od around 20000 items. And it is updated every few days when he gets a catalog from the supplier. It's supposed to work like this: if there already is a...
3
by: David | last post by:
Hi, I have a page which lets me select a user from a list by checking a check box next to the specific user and pressing a submit button. The Check box holds the value = 'UserID'. A new form...
9
by: Curtis Stanford | last post by:
I'm in a situation where I need to load an ASCII file into a database. No sweat so far right? The records are indexed by date and I have a unique index on date. The ASCII can overlap, meaning it...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
1
by: MHenry | last post by:
Hi, I have a table with duplicate records. Some of the duplicates need to be eliminated from the table and some need not. A duplicate record does not need to be eliminated if the one record...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
11
by: Sandy | last post by:
Hello - Thought I was almost done with my project and then a back arrow button issue raised its ugly head. Once a user fills out a form and submits it (done via stored procedure into a Sql...
1
by: G Gerard | last post by:
Hello I am trying to update a table (TableB) using records from a second table (TableA)
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.