Try
SELECT * FROM mytable mt1
WHERE mt1.DaysOff = 2
AND NOT EXISTS ( SELECT * FROM mytable mt2
WHERE mt2.DaysOff = 2
AND mt2.CustomerID <> mt1.CustomerID
AND mt2.DateRegistered < mt1.DateRegistered)
SELECT TOP 1 * FROM mytable mt1
WHERE mt1.DaysOff = 2
ORDER BY DateRegistered
>
>TABLEA
>-------
>CustomerID -unique identifier
>Name - varchar
>DateRegistered - datetime
>#ofDaysOff - int
>#FreeDaysOff - int
>
>My problem is that I need to get to get the employeeid of most senior employee with a criteria of 2 days off.
>
>I have tried this query but I dont get the correct date
>
>DECLARE @customerid as varchar(100)
>SELECT @customerid = customerid, MIN(DateRegistered) FROM
>TABLEA WHERE #ofDaysOff = 2
>GROUP BY customerid
>
>
>Thanks for your help.
>
>A
--sb--