Hi, welcome to the forum!
It's considered polite to post directly usable data that can be used to test the code we write, rather than just a display of the data. Like this:
CREATE TABLE #Employee ( ID int NOT NULL, Name varchar(100) NOT NULL );
INSERT INTO #Employee VALUES
(1, 'John Smith'),
(2, 'John Doe');
CREATE TABLE #SystemAppUse ( ID int NOT NULL, UseType smallint NOT NULL, EmployeeID int NOT NULL, CreatedDate datetime NOT NULL )
INSERT INTO #SystemAppUse VALUES
(1, 4, 1, '20210414 16:49:12'),
(2, 1, 1, '20210414 16:48:57');
CREATE TABLE #UseType ( ID smallint NOT NULL, Description varchar(100) NOT NULL );
INSERT INTO #UseType VALUES
(1, 'Admin-Login'),
(2, 'Employee-Login'),
(3, 'Cashier-Login'),
(4, 'Logout');
With that out of the way, here's the actual code to calc the work hours:
SELECT SAU.EmployeeID,
CAST(SUM(DATEDIFF(SECOND, '20100101', SAU.CreatedDate) *
CASE WHEN UT.Description LIKE '%Logout%' THEN 1 ELSE -1 END)
/ 60.0 / 60.0 AS decimal(9, 2)) AS Hours_Worked,
CASE WHEN
SUM(CASE WHEN UT.Description LIKE '%Logout%' THEN 0 ELSE 1 END) =
SUM(CASE WHEN UT.Description LIKE '%Logout%' THEN 1 ELSE 0 END)
THEN 'Login and Logout counts match, hours are good.'
ELSE 'Login and Logout counts do NOT match, hours could NOT be accurately calculated.' END AS Message
FROM #SystemAppUse SAU
INNER JOIN #UseType UT ON UT.ID = SAU.UseType
GROUP BY SAU.EmployeeID