I have the following data examples:

It basically displays the following hierarchy:

And I should get from him all (S) tart (E) nd pairs similar to this (order is not important):

My solution is to click all the values in the source table variable:
- Select all auxiliary (S) tart (E) pairs.
- Insert them into the destination table variable
- Remove them from the source table variable
- Follow step 1 if the source table variable is not empty.
My questions is: can anyone come up with an alternative solution? In my real situation, I have more rows and am worried about deleting and pasting into table variables.
Below is the below script: sample data:
DECLARE @DataSource TABLE
(
[ID] TINYINT
,[Type] CHAR(1)
)
INSERT INTO @DataSource ([ID], [Type])
VALUES (3,'S')
,(6,'E')
,(7,'S')
,(10,'S')
,(13,'E')
,(14,'E')
,(15,'S')
,(16,'S')
,(17,'S')
,(19,'S')
,(20,'S')
,(26,'E')
,(27,'E')
,(28,'E')
,(29,'E')
,(30,'E')
,(31,'S')
,(32,'S')
,(35,'E')
,(36,'S')
,(38,'E')
,(39,'S')
,(40,'S')
,(44,'E')
,(45,'E')
,(46,'E')