select pkid,userid, max(case when sno=1 then phonenumber end) as phno1, max(case when sno=2 then phonenumber end) as phno2, max(case when sno=3 then phonenumber end) as phno3 from ( select row_number() over(order by userid) as sno ,* from @t) as t group by pkid,userid