Q:

Select 1st and 2nd Record before record X

SQL Server 2008-12
I have table: 
InteractionKey char(18)
dEventTime datetime
SeqNo int
cEventData1

There will be multiple entries per InteractionKey - dEventTime only goes out to the Seconds and SeqNo is incremented if two entries occur on the same second.
What I need to do is select the First and Second record BEFORE the record where 
cEventData1 = 'Disconnect'
The final product will give me a count of occurrences grouped by cEventData1.
I am currently using a cursor (will update with cursor source momentarily) I would like to use a CTE - but I really struggle with understanding them... 
Any ideas would be appreciated!
Update with Data Sample
INTERACTIONKEY      dEventTime          SeqNo   cEventData1

100186322420130722  2013-07-22 11:50:49.000     1   EnterPassword
100186322420130722  2013-07-22 11:50:49.000     2   CheckPassword
100186322420130722  2013-07-22 11:50:49.000     3   Attendant Disconnect

The result of the query would ideally tell me - : NOTE The Action column here can be simply 'Attendant Disconnect'  as Action 
cEventData1     Action                   Count
CheckPassword   Attendant Disconnect        1

Here is the query I ended up going with based upon the below answer
    SELECT DISTINCT t1.InteractionKey,
        DisconnectTime = t1.dEventTime,
        PreviousEventTime = t2.dEventTime,
        PreviousEvent = t2.cEventData1,
        t2.SeqNo
FROM    IVRHistory t1
        OUTER APPLY
        (   SELECT  TOP 1 t2.dEventTime, t2.SeqNo, t2.cEventData1
            FROM    IVRHistory t2
            WHERE   t1.InteractionKey = t2.InteractionKey
            AND     t1.dEventTime >= t2.dEventTime
            AND     t1.SeqNo > t2.SeqNo
            AND     t2.cEventData1 <> 'Attendant Disconnect'
            ORDER BY t2.dEventTime DESC, t2.SeqNo DESC
        ) t2
WHERE   t1.cEventData1 = 'Attendant Disconnect'

A:

I would approach this using APPLY:
SELECT  t1.InteractionKey,
        DisconnectTime = t1.dEventTime,
        PreviousEventTime = t2.dEventTime,
        PreviousEvent = t2.cEventData1,
        t2.SeqNo
FROM    T t1
        OUTER APPLY
        (   SELECT  TOP 2 t2.dEventTime, t2.SeqNo, t2.cEventData1
            FROM    T t2
            WHERE   t1.InteractionKey = t2.InteractionKey
            AND     t1.dEventTime > t2.dEventTime
            ORDER BY t2.dEventTime DESC
        ) t2
WHERE   t1.cEventData1 = 'Disconnect';

This will give you the two records immediately preceeding the disconnect event. If you need more than two records if there are duplicate times you can use TOP 2 WITH TIES.
Without your sample input and output I am guessing a bit, but from what you have said your final aggregate would be:
SELECT  t2.cEventData1,
        Occurances = COUNT(*)
FROM    T t1
        OUTER APPLY
        (   SELECT  TOP 2 t2.dEventTime, t2.SeqNo, t2.cEventData1
            FROM    T t2
            WHERE   t1.InteractionKey = t2.InteractionKey
            AND     t1.dEventTime > t2.dEventTime
            ORDER BY t2.dEventTime DESC
        ) t2
WHERE   t1.cEventData1 = 'Disconnect'
GROUP BY t2.cEventData1;

