Helo Dude Try This ....

Declare @matrix AS TABLE (courseid NVARCHAR(10),semid NVARCHAR(10),roomno NVARCHAR(10),studentid NVARCHAR(10))
INSERT INTO @matrix (courseid,semid,roomno,studentid) VALUES
('[1493]','[3]','[A-307]','[1012]')
INSERT INTO @matrix (courseid,semid,roomno,studentid) VALUES
('[1493]','[3]','[A-307]','[1013]')
INSERT INTO @matrix (courseid,semid,roomno,studentid) VALUES
('[1493]','[3]','[A-307]','[1014]')
INSERT INTO @matrix (courseid,semid,roomno,studentid) VALUES
('[1493]','[5]','[B-407]','[1045]')
INSERT INTO @matrix (courseid,semid,roomno,studentid) VALUES
('[1493]','[5]','[B-407]','[1046]')
;WITH Hierarchy(CourseID3,SemID3,RoomNo3,StudentID3,CourseID5,SemID5,RoomNo5,StudentID5)
AS
(
SELECT courseid,semid,roomno,studentid,'','','','' FROM @matrix WHERE semid = '[3]'
union ALL
SELECT '','','','',courseid,semid,roomno,studentid FROM @matrix WHERE semid ='[5]'
)
SELECT CourseID3 [courseid],
SemID3 [semid],
RoomNo3 [roomno],
StudentID3 [studentid],
CourseID5 [courseid],
SemID5 [semid],
RoomNo5 [roomno],
StudentID5 [studentid] FROM Hierarchy

[1493] [3] [A-307] [1012] [1493] [5] [B-405] [1145]

but not

[1493] [3] [A-307] [1012] [1493] [5] [B-405] [1146]?