|
-
May 30th, 2007, 05:55 AM
#7
Re: Simple Max function(beginner)
Code:
UPDATE BFCD_Designs
SET BFCD_Designs.EndDt = #5/30/2007#
WHERE
BFCD_Designs.EndDt is Null
AND BFCD_Designs.designid in
(
SELECT BFCD_Designs.DesignID
FROM BFCD_Designs INNER JOIN
(SELECT BFCD_Designs.DesignID,
Max(BFCD_Designs.Revision) AS MRevision
FROM BFCD_Designs
GROUP BY BFCD_Designs.DesignID
) AS sq
ON BFCD_Designs.revision = sq.mrevision
AND BFCD_Designs.designid = sq.designid
)
The bit in bold forces only those not already end dated to have a date.
I am joining all designs to the max revision per design id from all designs and returning only the designID.
This then goes into the where clause filter to tell the db which records to update.
Since your primary key is not one field, the design id is repeated more than once, you need to use two fields to find the row. However as it is a subquery (joining on the update means you cannot update (at least in Access)) it returns only a list of DesignIds, so I added the filter in bold so it will only update those not already end dated.
Personal preference would be :
Designs table - designs information
Revisions table - Design id and revision <- might hold the start / end for revision - Or at least a start date?
UserImp table - those that need checking for updates
Either method, as long as it does the job and works is good. It also depnds on how you are getting the users to interact with it.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|