Complex Pivot - Based on Previous Row value

I got a transactional table which has data for each and every minute. Have to Grouping this table and do a Pivot based on a Row value. Let me list the Example and Output below. Key value is "CH5".

TableA: (Input)
[Time] [Channel]
19.30 CH1
19.31 CH2
19.32 CH5
19.32 CH4
19.33 CH1
19.34 CH5
19.35 CH5
19.36 CH5
19.37 CH3
19.38 CH2
19.43 CH5
19.45 CH6

Output: (Pivot table based on CH5 - Previous to CH5 must be in the rows with Order. Here Source Channel will be always CH5. And an additional Next channel to be displayed. (its restricted to one Channel). Previous it must be till CH5 Occurs.

OUTPUT:

[Time] [SourceChannel] [PreCH1] [PreCH2] [PreCH3] [PreCH4] [NEXTCH]
19.32 CH5 CH2 CH1 NULL NULL CH4
19.34 CH5 CH1 CH4 NULL NULL
19.35 CH5 NULL NULL NULL NULL
19.36 CH5 NULL NULL NULL NULL CH3
19.43 CH5 CH2 CH3 NULL NULL CH6

Above output has based on CH5. Following First Channel will be pivoted for the NextCH, Previous Time channels will be pivoted into PreCH columns till CH5 occurs..

Try:

DECLARE @TableA table([Time] time, [Channel] char(3));
INSERT @TableA ( [Time], Channel )
VALUES 
   ( '00:19:30', 'CH1'  )
 , ( '00:19:31', 'CH2' )
 , ( '00:19:32', 'CH5' )
 , ( '00:19:32', 'CH4' )
 , ( '00:19:33', 'CH1' )
 , ( '00:19:34', 'CH5' )
 , ( '00:19:35', 'CH5' )
 , ( '00:19:36', 'CH5' )
 , ( '00:19:37', 'CH3' )
 , ( '00:19:38', 'CH2' )
 , ( '00:19:43', 'CH5' )
 , ( '00:19:45', 'CH6' );
 SELECT
     Substring(Convert(varchar(10), ta.Time, 114), 4, 5) [Time] 
   , ta.Channel BaseCh
   , ta2.Channel PreCh1
   , ta3.Channel PreCh2
   , ta4.Channel PreCh3
   , ta5.Channel PreCh4
   , ta6.Channel NextCh
FROM
   @TableA ta
LEFT JOIN
   @TableA ta2 ON DateAdd(Second, -1, ta.Time) = ta2.Time AND ta2.Channel <> 'CH5'
LEFT JOIN                 
   @TableA ta3 ON DateAdd(Second, -2, ta.Time) = ta3.Time AND ta3.Channel <> 'CH5'
LEFT JOIN                 
   @TableA ta4 ON DateAdd(Second, -3, ta.Time) = ta4.Time AND ta4.Channel <> 'CH5'
LEFT JOIN                 
   @TableA ta5 ON DateAdd(Second, -4, ta.Time) = ta5.Time AND ta5.Channel <> 'CH5'
LEFT JOIN                 
   @TableA ta6 ON DateAdd(Second, 1, ta.Time) = ta6.Time
WHERE ta.Channel='CH5' ;

image