The naming of the column
duration
has to come after the
END
of the
CASE
statement
case when LastLoggedInDetails.LoggedOutTime is not null then
CONVERT(VARCHAR(100),DATEDIFF(hour,LastLoggedInDetails.LoggedInTime ,LastLoggedInDetails.LoggedOutTime ))+' Hours '+
CONVERT(VARCHAR(100),DATEDIFF (minute,LastLoggedInDetails.LoggedInTime ,LastLoggedInDetails.LoggedOutTime )%60) +' Minutes'
when LastLoggedInDetails.LoggedOutTime is null then 'Running...'
end as Duration