select tbl2.id,tbl2.TitleName,tbl1.[1],tbl1.[2],tbl1.[3],tbl1.[4] from
(select * from (SELECT [MainId] ,[SAnswer] ,Row_Number() OVER(partition by mainid order by MainId,sanswer) as row_num FROM [dbo].[SingleProblemNewDetail]) t pivot(max([SAnswer]) for row_num in ([1],[2],[3],[4])) pt) tbl1 inner join [dbo].[SingleProblemNew] tbl2 on tbl2.id=tbl1.[MainId]