473,385 Members | 1,912 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.

how to dup a record with changes

Could anyone help write an SQL statement to take this:

Table X ( key, Money, TheDate, first, last, ...) =
( 1, $1, #jan 4, 2006#, 'fred', 'willard', ...),
( 2, $4, #apr 1, 2006#, 'emanuel', 'lewis', ...),
( 3, $7, #may 8, 2006#, 'your', 'mama', ...)

and turn it into this:

Table X ( key, Money, TheDate, first, last, ...) =
( 1, $1, #jan 4, 2006#, 'fred', 'willard', ...),
( 2, $4, #apr 1, 2006#, 'emanuel', 'lewis', ...),
( 3, $7, #may 8, 2006#, 'your', 'mama', ...),
( 4, -$4, #jul 28, 2006#, 'emanuel', 'lewis', ...)

Where key is the auto incrementing primary key.

I'm copying record to, but need to negate the Money and use todays date
as TheDate in the new record, but copying all of the rest of the record
verbatim. The statement needs to not refer to the fields that don't
change by name as more fields may be added later and this code needs to
keep working properly without having to be modified to deal with table
schema growth.

The current code in my project does a query to get record 2, runs
another query to get the who table X in writable mode, adds a new
record, iterates through the fields copying them all (except the
first/key), then changes the fields that need to be different by
referencing them by name. I think it's ugly, but I can't figure a way
to fix it in a pretty way. This seems like it should have a very nice
"why didn't I think of that" solution, but no one else seems to be able
come up with anything either.

Thank you,
Nathan
Jul 28 '06 #1
4 1313
Nathan Moore <na**********@cox.netwrote in
news:gntyg.166531$k%3.42635@dukeread12:
I'm copying record to, but need to negate the Money and use
todays date as TheDate in the new record, but copying all of
the rest of the record verbatim. The statement needs to not
refer to the fields that don't change by name as more fields
may be added later and this code needs to keep working
properly without having to be modified to deal with table
schema growth.
Copying all the other fields verbatim! That's because of poor
database design. All the fields that are constant should be in a
separate table that's linked to the first by a reference ID.

So you create a record and add the one piece of common
information, the 'Foreign Key' to your constants, and no matter
what fields you add to that table, you don't have to change
anything in the code to add a record to this one.
of that" solution, but no one else seems to be able come up
with anything either.
That's because you are trying to design a spreadsheet instead of
a database.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 28 '06 #2
Hey Bob,
I know that's bad DB design, but I didn't design it, and I can't change
it.
This table is really more of a list/log than a spreadsheet. Things are
appended but never taken out.
Also my example was designed to be easy for whoever read the question
to comprehend without having to think about that the actual table that
I'm working on has foreign keys in it that is part of the data that is
copied verbatim. It would be kinda silly to have a table that was just
foreign keys, but that's what it would take to be really well designed
(in the theoretical sense) if it were more than just one foreign key.
Anyway, I have a table* that I need this type of operation done on and
it seems too simple for there not to be a swift way to do it.


* In a product in thousands of offices around the US and I can't change
the schema except for just tacking stuff on top of what's already there
(and even then only on special occasions) as per company rules.

Jul 28 '06 #3
"na*******@gmail.com" <na*******@gmail.comwrote in
news:11**********************@i42g2000cwa.googlegr oups.com:
Hey Bob,
I know that's bad DB design, but I didn't design it, and I
can't change it.
This table is really more of a list/log than a spreadsheet.
Things are appended but never taken out.
Also my example was designed to be easy for whoever read the
question to comprehend without having to think about that the
actual table that I'm working on has foreign keys in it that
is part of the data that is copied verbatim. It would be
kinda silly to have a table that was just foreign keys, but
that's what it would take to be really well designed (in the
theoretical sense) if it were more than just one foreign key.
Anyway, I have a table* that I need this type of operation
done on and it seems too simple for there not to be a swift
way to do it.


* In a product in thousands of offices around the US and I
can't change the schema except for just tacking stuff on top
of what's already there (and even then only on special
occasions) as per company rules.

You can do it in code. Set up a recordset that takes the current
record. set up a second recordset that contains a new record.
Loop through the fields() index to copy all fields. Then null
the fields that you don't want to copy.

Air code:

rsto.addnew
'fields are numbered 0 to count-1, 0 is autonumber=skip
For idx = 1 to rsFrom.fields.count - 1
rsTo.fields(idx) = rsFrom.fields(idx)
next idx
rsTo.fields(datefield) = null
rsto.update

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 28 '06 #4
That's kinda what is already in the program, but thanks anyway. I was
wanting something that would be done entirely inside the DBMS without
copying the records to/from the application (even though this is an
Access DB, so it's just library code).

Thanks anyway,
Nathan

Jul 29 '06 #5

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

Similar topics

5
by: Ryan | last post by:
I have some software (written in Delphi 5) which has been working for several months without a problem. I have been given a copy of the database on our development server (SQL 7) and have...
2
by: RC | last post by:
I am getting the following error message. "Write Conflict this record has been changed by another user since you started edting it. If you save the record, you will overwrite the changes...." I...
4
by: Jim M | last post by:
Two questions: 1) I have a scheduling application (Access 2002) that allows multiple staff members to edit notes on their meetings and appointments from their offices. A receptionist views a...
3
by: pcPirate | last post by:
Hi, I have an application, the user are able to change records in this application. Also, there's a button called "What If". After the user pressed the "What If" button, the user may change...
19
by: rich | last post by:
I am building an app using php and postgresql. My questionis this. How do you handle people wanting to make parallel changes to a record. Since in web apps you are doing a select, bring over a...
5
by: Clownfish | last post by:
I have a report that joins 12 external tables, and works great. However, there is a time when I wish to skip printing a particular record. Background: The 12 tables all have the same fields,...
2
by: rockdc1981 | last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the codes work out fine separately. Code for Audit...
11
by: Don Barton | last post by:
I am trying to update a table using VBA and SQL. A form is filled out with user ID and PW, then these data are sent to global variables. The global variables are used to create a record in...
11
by: andrewdb | last post by:
I have been working with a database that was already created by somebody else, who now no longer works here, so I cant ask any questions. None the less, there is a table 'Ascertainment' which...
19
by: emanning | last post by:
Using Access 2003 and using a form that's mostly bound. I need a way to tell if user-1 is on the record when user-2 tries to open the same record, w/o waiting for the user-1 to save the record...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.