Maybe:with cte1 as (select * ,RowNumber-1 as RowNumberPrev from yourtable where Pic is null union all select a.RowNumber ,b.Pic ,a.Description ,a.RowNumberPrev-1 as RowNumberPrev from cte1 as a inner join yourtable as b on b.RowNumber=a.RowNumberPrev where a.Pic is null ) ,cte2 as (select * from yourtable where Pic is not null union all select RowNumber ,Pic ,Description from cte1 where Pic is not null )select a.Pic ,stuff((select ' - '+b.Description from cte2 as b where b.Pic=a.Pic order by b.RowNumber for xml path('') ),1,3,'' ) as Description from cte2 as a group by a.Pic order by a.Pic