mastros
You can do this without a cursor, but this method does require that you don't have bad data. Let me explain... If EVERY login has a corresponding logout and the date/times match up nicely, you can use set based operations to perform this query.
What I present below will create a table variable to store your data. If this method works for you, simply remove the @Temp variable and change the subsequent query to pull the data from your table.
-- Setting up some sample data.
Declare @Temp Table(UserAction VarChar(20), UserName VarChar(20), ActionTime DateTime)
Insert Into @Temp Values('login', 'user1', '2007-02-15 10:21:35.590')
Insert Into @Temp Values('login', 'user2', '2007-02-15 10:21:36.100')
Insert Into @Temp Values('logout','user1', '2007-02-15 10:22:45.100')
Insert Into @Temp Values('login', 'user3', '2007-02-15 10:23:23.100')
Insert Into @Temp Values('logout','user2', '2007-02-15 10:27:54.436')
Insert Into @Temp Values('logout','user3', '2007-02-15 10:30:03.237')
-- Actual query would begin here.
Declare @Actions Table(RowId Integer Identity(1,1) Primary Key Clustered, UserAction VarChar(20), UserName VarChar(20), ActionTime DateTime)
Insert Into @Actions (UserAction, UserName, ActionTime)
Select UserAction, UserName, ActionTime
From @Temp
Order By UserName, ActionTime
Select A.UserName, B.ActionTime - A.ActionTime
From @Actions As A
Inner Join @Actions As B
On A.UserName = B.UserName
And A.RowId = B.RowId - 1
And A.UserAction = 'Login'
And B.UserAction = 'Logout'