I am trying to figure out the solution using co-related sub-query but somehow getting stuck with 'odd-dates' instead of # of max(concurrent users) and sessions for particular applications. Any help would be really appreciable.
Below is the reference query and output snapshot:-
SELECT ExtensionID, ClientCode, LoginTime, LogoutTime
FROM ( SELECT ExtensionID, ClientCode, AuditDate as LoginTime, Change, isnull(LEAD(AuditDate) OVER (PARTITION BY ExtensionID ORDER BY AuditDate), GETDATE()) as LogoutTime
FROM (SELECT ExtensionID, ClientCode, AuditDate, case when AssignedEmployeeID is not null then 1 when AssignedEmployeeID is null then -1 else 0 end as change
from Focus.Mallaka.TollExtensions as ext with (nolock)
WHERE AuditDate between DATEADD(Day,-7,GETDATE()) and GETDATE()
) as subQ
) as LeadSubQuery
WHERE Change = 1
order by ExtensionID, LoginTime;