dbTalk Databases Forums  

last record

comp.databases.ms-access comp.databases.ms-access


Discuss last record in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
kevcar40
 
Posts: n/a

Default last record - 08-18-2010 , 07:49 AM






hi i have a table containing
a list of components and the status
table
index, fldcomponnum , fldstatus

the index is an autonumber
the fldcomponnum hold the component number
fldstatus holds the status of the component
the status can be one of three states "Minor", "Offload", "Onload"
the component can have mulitple records,could be anyone one or all the
states and a new entry is created for each state.
i.e
index fldcomponnum fldstatus
1 1234 Offload
2 1234 Onload
3 1234 Minor
4 1234 Offload
5 2365 Offload
6 3365 Offload
7 3365 Onload


what i would like to do is return the last occurr for each record
where the status is offload and it has not been onloaded
so the result woud be

index fldcomponnum fldstatus
4 1234 Offload
5 2365 Offload

index number 7 would be ignored because the component has been
onloaded


any ideas as to the best way to do this

thanks


kevin

Reply With Quote
  #2  
Old   
John Spencer
 
Posts: n/a

Default Re: last record - 08-18-2010 , 08:05 AM






You might try the following query. Make sure you have an index on each of the
three fields.

If there is a large number of records, this query may be too slow to be
useful. I used the name ComponentStatus as the table name.

SELECT Max([index]) as HighIndex, fldCompNum, "Offload" as TheStatus
FROM ComponentStatus
WHERE fldStatus = "Offload"
AND Not Exists
(SELECT *
FROM ComponentStatus as Temp
WHERE Temp.fldCompnum = ComponentStatus.fldCompNum
AND Temp.[Index] > ComponentStatus.[Index]
AND Temp.FldStatus = "OnLoad")
GROUP BY fldCompNum

By the way INDEX is not a good field name since Index is a reserved word in
Access. Using reserved words can cause problems unless you surround them with
square brackets.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

kevcar40 wrote:
Quote:
hi i have a table containing
a list of components and the status
table
index, fldcomponnum , fldstatus

the index is an autonumber
the fldcomponnum hold the component number
fldstatus holds the status of the component
the status can be one of three states "Minor", "Offload", "Onload"
the component can have mulitple records,could be anyone one or all the
states and a new entry is created for each state.
i.e
index fldcomponnum fldstatus
1 1234 Offload
2 1234 Onload
3 1234 Minor
4 1234 Offload
5 2365 Offload
6 3365 Offload
7 3365 Onload


what i would like to do is return the last occurr for each record
where the status is offload and it has not been onloaded
so the result woud be

index fldcomponnum fldstatus
4 1234 Offload
5 2365 Offload

index number 7 would be ignored because the component has been
onloaded


any ideas as to the best way to do this

thanks


kevin

Reply With Quote
  #3  
Old   
kevcar40
 
Posts: n/a

Default Re: last record - 08-18-2010 , 08:48 AM



On 18 Aug, 14:05, John Spencer <JSPEN... (AT) Hilltop (DOT) umbc> wrote:
Quote:
You might try the following query. *Make sure you have an index on eachof the
three fields.

If there is a large number of records, this query may be too slow to be
useful. *I used the name ComponentStatus as the table name.

SELECT Max([index]) as HighIndex, fldCompNum, "Offload" as TheStatus
FROM ComponentStatus
WHERE fldStatus = "Offload"
AND Not Exists
* * (SELECT *
* * *FROM ComponentStatus as Temp
* * *WHERE Temp.fldCompnum = ComponentStatus.fldCompNum
* * *AND Temp.[Index] > ComponentStatus.[Index]
* * *AND Temp.FldStatus = "OnLoad")
GROUP BY fldCompNum

By the way INDEX is not a good field name since Index is a reserved word in
Access. *Using reserved words can cause problems unless you surround them with
square brackets.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County



kevcar40 wrote:
hi i have a table containing
a list of components and the status
table
*index, * * fldcomponnum , *fldstatus

the index is an autonumber
the fldcomponnum hold the component number
fldstatus holds the status of the component
the status can be one of three states *"Minor", "Offload", "Onload"
the component can have mulitple records,could be anyone one or all the
states and a new entry is created for each state.
i.e
index * * * fldcomponnum * * * fldstatus
1 * * * * * * * * * 1234 * * * * * * * * Offload
2 * * * * * * * * * 1234 * * * * * * * * Onload
3 * * * * * * * * * 1234 * * * * * * * * *Minor
4 * * * * * * * * * 1234 * * * * * * * * Offload
5 * * * * * * * * * 2365 * * * * * * * * Offload
6 * * * * * * * * * 3365 * * * * * * * * Offload
7 * * * * * * * * * 3365 * * * * * * * * Onload

what i would like to do is return the last occurr for each record
where the status is offload and it has not been onloaded
so the result woud be

index * * * fldcomponnum * * * fldstatus
4 * * * * * * * * * 1234 * * * * * * * * Offload
5 * * * * * * * * * 2365 * * * * * * * * Offload

index number 7 would be ignored because the component has been
onloaded

any ideas as to the best way to do this

thanks

kevin- Hide quoted text -

- Show quoted text -
thank you very much
for your help it works a treat

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.