Thanks, but I actually managed to do it using the following. It was so easy in the end:
--------------------
select top(@number)
row_number() over (order by count(datedifference) desc)as [Rank],
datedifference,
COUNT(datedifference) as Number
from #search
group by...