i have a time clock application that registers employes Attendance at work,
i was trying to set the visibility of “Enter” imageButton
(entrance e.g “Timein” field ) to hidden based on a query
so if there was no timeout in last record that has a TimeIn for the current UserId then the Enter button will be hidden
this is the table : (tId is PK IDENTITY)

so based on those records for example , the last (top 1) is not signed out so the user will not get to see the Enter button, that allows user to sign in, cause there was no last action of TimeOut
working from asp.net C# code behind i was trying to work a solution using datedIff as a query :
but i guess i am missing something here
please don’t take it to account if this is the wrong approach i just wanted to show.. i did try though if there’s a better way to achive what i need then just disregard that query
select isnull((SELECT TOP 1 case when [TimeOut] is null then '' else convert(nvarchar,[TimeOut]) end FROM tblTime WHERE datediff(day,TimeOut,getdate())=0 and UserId =3571 ORDER BY tId DESC),'')
This finds the record with the highest tid for the userId.
but ids aren’t a good choice for getting the most recent record. Probably you want something more along these lines, but it depends on the meaning of the columns and if there could be duplicates…:
or you could put the subquery as part of the FROM clause.