Nice script. Three(minor) comments:
First, ** While running the below query if you find any query which ** is repeated in the comment header.
Second, I don't understand why you have WHEN [spn].[open_tran] = 2 THEN, couldn't you remove that and change
WHEN [spn].[open_tran] >= 3 THEN
to
WHEN [spn].[open_tran] >= 2 THEN?
Third, the case below will never happen
CASE WHEN [spn].[open_tran] = 0
because of the filter in the WHERE clause:
AND [spn].[open_tran] <> 0;
thanks