Hey David, here is some code that actually is the complete correct answer to your question. As others have mentioned, there is a bug in the USR5 table that distorts the time if the user logged in before 10 o'clock AM. For example, if the time reads 92:23:10 then move the colon so it reads basically 09:22:31.
I have tested this in a production environment and can confirm the time bug and its behavior. I spent a good deal of time making sure I was right. Hope this helps you out!
Thanks, Peter
--CODE BY SBOHUB.COM
WITH summary AS (
SELECT T1.U_NAME,
LEFT(T0.Date, 12) AS Date,
SUBSTRING (CAST ([Time] as char), 1,2) + ':' +SUBSTRING (CAST ([Time] as char), 3,2) + ':' +SUBSTRING (CAST ([Time] as char), 5,2) AS Time,
CAST(ROW_NUMBER() OVER(PARTITION BY T0.UserCode
ORDER BY T0.Date DESC, T0.Time DESC)AS INT) AS Row
FROM USR5 T0 INNER JOIN OUSR T1 ON T0.UserCode = T1.USER_CODE WHERE T0.Date NOT LIKE '%3913%' AND T0.Action = 'I' AND T0.UserCode <> 'B1i')
SELECT S.*
FROM summary S
WHERE Row = 1