Hi,
Follow the below steps:
1. Remove all blank spaces from AccessCardNo and EntryExit field (if any blank space)
Note: I just copy your provided table value and got blank space so remove them.
2. Execute the below query, it will give you Total Seconds stayed in office of a particular employee
select datediff(s,(SELECT TOP 1 RecordedTime AS Entry FROM tblTest Where AccessCardNo='0050' AND EntryExit='A0001'
ORDER BY RecordedTime ASC),(SELECT TOP 1 RecordedTime AS Out FROM tblTest Where AccessCardNo='0050' AND EntryExit='A0002'
ORDER BY RecordedTime DESC)) AS TotalSecondsInOffice
3. Keep the value in a variable
4. If you divide the result by 3600 then you will get hour
5. If you need Minute then divide the Remainder value by 60 then you will get Minute
Note: If you need only hour then run the below query
SELECT DATEDIFF(s,(SELECT TOP 1 RecordedTime AS Entry FROM tblTest Where AccessCardNo='0050' AND EntryExit='A0001'
ORDER BY RecordedTime ASC),(SELECT TOP 1 RecordedTime AS Out FROM tblTest Where AccessCardNo='0050' AND EntryExit='A0002'
ORDER BY RecordedTime DESC))/3600 AS TotalHoursInOffice
Thanks,
Mamun