All pastes #921238 Raw Edit

Mine

public text v1 · immutable
#921238 ·published 2008-02-27 22:09 UTC
rendered paste body
table REGISTRERINGER:

columns:
id (autoincrement)
employeeID
orderNr
regStart
regStop


Function:
When an employee adds a record using a form the new form will look like this:
XX | 1234 | 54321 | NOW() | NULL |

If the _SAME_ employee adds a new record (1234) regStop will be updated with NOW() on the previous record to 'close' it, and the new record will be inserted liked.. 

XY | 1234 | 64283 | NOW()| NULL |

:-/ Now.. this works fine untill i start having more than one employee adding records.. 

any help on such a query? what i have now is something like.. 

SELECT registreringer.medarbejderID, registreringer.regStop
FROM registreringer
WHERE (((registreringer.medarbejderID) In (SELECT [medarbejderID] FROM [registreringer] As Tmp GROUP BY [medarbejderID] HAVING Count(*)>1 )) AND ((registreringer.regStop) Is Null))
ORDER BY registreringer.medarbejderID;

But now this returns two.. so when i updated regStop based on that, i'll close 2x rows. (for 2 employees, instead of just closing the employee adding a new record)