473,549 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

automatically update fields in a table using values within the same table

I have a table that is shown below in ORIGINAL TABLE. It is common for
the VEHICLE # field to have repeating vehicles (ID 3,4,5 & 8,9).
Usually the Vehicle will have SHIPDATE, DATE_RECEIVED, and
DATE_ORDERED for the first entry, after that is could be null (ID 4 &
5). What I would like to do is for a query or VB code to look into the
ORIGINAL TABLE, find the duplicating VEHICLES. Where ever
DATE_RECEIVED or DATE_ORDERED is empty, automatically update it using
DATE_RECEIVED and DATE_ORDERED from the previous entry of the same
vehicle( but SHIPDATE MUST BE THE SAME!!).

ORIGINAL TABLE
ID VEHICLE # SHIPDATE DATE_RECEIVED DATE_ORDERED
1 BF16 5/1/2004 4/30/2004 4/28/2004
2 BF22 5/4/2004 5/1/2004 4/31/2004
3 GT15 5/15/2004 5/10/2004 5/9/2004
4 GT15 5/15/2004
5 GT15 5/15/2004
6 RV66 5/19/2004 5/18/2004 5/17/2004
7 RV68 5/19/2004 5/18/2004 5/17/2004
8 JM40 5/20/2004 5/18/2004 5/16/2004
9 JM40 5/22/2004
10 BX12 5/29/2004 5/25/2004 5/20/2004

RESULTING TABLE
ID VEHICLE # SHIPDATE DATE_RECEIVED DATE_ORDERED
1 BF16 5/1/2004 4/30/2004 4/28/2004
2 BF22 5/4/2004 5/1/2004 4/31/2004
3 GT15 5/15/2004 5/10/2004 5/9/2004
4 GT15 5/15/2004 5/10/2004 5/9/2004
5 GT15 5/15/2004 5/10/2004 5/9/2004
6 RV66 5/19/2004 5/18/2004 5/17/2004
7 RV68 5/19/2004 5/18/2004 5/17/2004
8 JM40 5/20/2004 5/18/2004 5/16/2004
9 JM40 5/22/2004
10 BX12 5/29/2004 5/25/2004 5/20/2004

Here, DATE_RECEIVED & DATE_ORDERED in rows ID 4,5 have been
automatically updated using values from row ID 3. Row ID 9 did not get
updated with using ID 8 because they have different SHIPDATE.

Any help is greatly appreciated. I cannot find a way to solve this at
all.

JIm
Nov 13 '05 #1
1 1860
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Untested query:

UPDATE [Original Table] As A LEFT JOIN [Original Table] As B
ON A.[Vehicle #] = B.[Vehicle #] AND A.[ShipDate] = B.[ShipDate]
SET B.Date_Received = A.Date_Received ,
B.Date_Ordered = A.Date_Ordered
WHERE A.Date_Received IS NOT NULL
AND A.Date_Ordered IS NOT NULL

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQUhvyYechKq OuFEgEQK/8gCg2qoWRj3ZWYQ hNMcwpdt8aS7oZM sAoKg4
ACtzwAVZxOhF6GQ o69TtM/U9
=awQD
-----END PGP SIGNATURE-----
Jimmy wrote:
I have a table that is shown below in ORIGINAL TABLE. It is common for
the VEHICLE # field to have repeating vehicles (ID 3,4,5 & 8,9).
Usually the Vehicle will have SHIPDATE, DATE_RECEIVED, and
DATE_ORDERED for the first entry, after that is could be null (ID 4 &
5). What I would like to do is for a query or VB code to look into the
ORIGINAL TABLE, find the duplicating VEHICLES. Where ever
DATE_RECEIVED or DATE_ORDERED is empty, automatically update it using
DATE_RECEIVED and DATE_ORDERED from the previous entry of the same
vehicle( but SHIPDATE MUST BE THE SAME!!).

ORIGINAL TABLE
ID VEHICLE # SHIPDATE DATE_RECEIVED DATE_ORDERED
1 BF16 5/1/2004 4/30/2004 4/28/2004
2 BF22 5/4/2004 5/1/2004 4/31/2004
3 GT15 5/15/2004 5/10/2004 5/9/2004
4 GT15 5/15/2004
5 GT15 5/15/2004
6 RV66 5/19/2004 5/18/2004 5/17/2004
7 RV68 5/19/2004 5/18/2004 5/17/2004
8 JM40 5/20/2004 5/18/2004 5/16/2004
9 JM40 5/22/2004
10 BX12 5/29/2004 5/25/2004 5/20/2004

RESULTING TABLE
ID VEHICLE # SHIPDATE DATE_RECEIVED DATE_ORDERED
1 BF16 5/1/2004 4/30/2004 4/28/2004
2 BF22 5/4/2004 5/1/2004 4/31/2004
3 GT15 5/15/2004 5/10/2004 5/9/2004
4 GT15 5/15/2004 5/10/2004 5/9/2004
5 GT15 5/15/2004 5/10/2004 5/9/2004
6 RV66 5/19/2004 5/18/2004 5/17/2004
7 RV68 5/19/2004 5/18/2004 5/17/2004
8 JM40 5/20/2004 5/18/2004 5/16/2004
9 JM40 5/22/2004
10 BX12 5/29/2004 5/25/2004 5/20/2004

Here, DATE_RECEIVED & DATE_ORDERED in rows ID 4,5 have been
automatically updated using values from row ID 3. Row ID 9 did not get
updated with using ID 8 because they have different SHIPDATE.


Nov 13 '05 #2

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

Similar topics

6
8324
by: Jason | last post by:
I need to populate a table from several sources of raw data. For a given security (stock) it is possible to only receive PARTS of information from each of the different sources. It is also possible to have conflicting data. I am looking to make a composite picture of a given security using the following rules: 1) The goal is to replace...
7
2978
by: Philip Mette | last post by:
I have been searching many postings and I cant seem to find anyone that has this answer so I decided to post. I am using SQL (Transact-SQL).If I have 2 tables with columns acct_num,activity_date,and pay_amt and I want to delete one instance of a record in table 1 for every instance of that record in table 2 how could I do that. For example. ...
4
1860
by: jean.ockert | last post by:
Greetings. Access version 2003 on an XP system I am using the template "Event Management" database as the primary database and need additional functionality added. I have a dance studio. Dance "events" do not change, only the months they occur. I have Attendee, EventTypes, Registration, and Classes tables. I need to add the...
1
1880
by: keliie | last post by:
I have a relatively simple (I assume) issue which I am at a complete loss to address. My issues is: I want to populate fields in my tables with summary data from the same table. Let me explain: tblItemDetails (contains data on food products purchased) Item_Description_ID (key, source link to tblMenuItemRecipe) Item_Unit_of_Measure...
0
1644
by: khoegen | last post by:
Folks, I am in the process of designing a database, within which I have created a table called "tblDOCUMENTS". As the title suggests, this is a list of documents (records) of varying types. I would like to cretae a many-to-many relationship 'within' the table. All of the records are related to zero, 1, or more 'other' records...all of which...
3
1802
by: Birky | last post by:
Do to multiple iterations of data contained in my Event_Log table I now find myself having to update all entries within my Element_Name column that are = “ “ to a Null value. This is necessary for when I am running reports and trying to group by this filed I am getting erroneous entries due to some values being null and some = to “ “. What is...
1
1686
by: lunas | last post by:
hi i have to update a table based on a criteria with value selected from another table. i am writting a java progg for it . i just want to know can it be done with one statement. my purpose is result set rs =select (ID) from Tab1 where colmB is null LOOP rs select ID2 from tab2 where colC=ID
2
1867
by: obs | last post by:
Hi all. I have two tables: Pages consists of an id field: PageId, and some other fields NewsTemplate consists of another id field: PageId , and some other fields I want to update PageId in NewsTemplate to get the value of the largest PageId in Pages, so I use the following code : SELECT MAX(PageId) AS maxPageId FROM Pages
3
19223
by: fionashaw | last post by:
I am trying to fix an issue for a customer which requires us to update a column in a table with the value in the column concatenated (||) with the value in another row in the same table. The table holds comments on data items, where the data is held in datasets. Each year a new dataset is created by copying the previous years dataset but there...
0
7542
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7827
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5110
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3514
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3494
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1961
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 we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.