Alaa,
You want the Agent State Detail table. Make a join based on two tables, one table which is the login, and one table which is the logout. Join the two based on agentID and any other conditions you require.
Example of login table:
SELECT agentID, eventDateTime AS loginTime, eventType
FROM dbo.AgentStateDetail AS ASD1
JOIN dbo.Resource AS r ON ASD1.agentID = r.resourceID
WHERE eventType = 2 AND r.dateInactive >= @startDateTime
Example of logout table:
SELECT agentID, eventDateTime AS logoutTime, eventType
FROM dbo.AgentStateDetail AS ASD2
JOIN dbo.Resource AS r ON ASD2.agentID = r.resourceID
WHERE eventType = 3 AND r.dateInactive >= @startDateTime
Join the two, do a date diff and you'll have the duration between the two states. In this example, ready/notready times. Change eventType to suit your needs.
Tanner Ezell
www.ctilogic.com