Perhaps this?
;with A (CC1, STR1) as
(
select top 3 count(*)
, substring(cmsg,15,20)
from #temp
group by substring(cmsg,5,10)
order by count(*) desc
)
select t.*
from #temp1 t
join A a on a.STR1 = substring(t.cmsg,5,10)
EDIT:
reposted - I forgot to include the "top 3" thing
Be One with the Optimizer
TG