plz try this .....This is not more efficent code but fullfill your need
declare @demo table(id int identity(1,1),columname int null)
insert into @demo(columname)
select yourcolumn from yourtable
declare @temp table(kid int identity(1,1),col1 int null,col2 int null,col3 int null)
declare @i int=1
declare @count int=0
declare @j int=1
declare @m int=0
set @count=(select count(*) from h_ptmast)
while(@i<=@count) begin
if(@j=1)begin
insert into @temp(col1)
select columname from @demo where id=@i
set @m=@m+1
end
else if(@j=2)begin
update @temp set col2=columname
from @demo where id=@i and kid=@m
end
else begin
update @temp set col3=columname
from @demo where id=@i and kid=@m
end
if(@j=3)begin
set @j=1
end
else begin
set @j=@j+1
end
set @i=@i+1
end
select col1,col2,col3 from @temp