Hi hazel14,
Join multiple tables and use the case statement like below sample example.
CREATE TABLE #Test ([Day] VARCHAR(10),[Period] INT,[Subject] VARCHAR(50))
INSERT INTO #Test VALUES ('Mon',1,'Chemistry')
INSERT INTO #Test VALUES ('Mon',2,'Physics')
INSERT INTO #Test VALUES ('Mon',3,'Math')
INSERT INTO #Test VALUES ('Mon',4,'CS')
INSERT INTO #Test VALUES ('Mon',5,'Lab1')
INSERT INTO #Test VALUES ('Mon',6,'Lab2')
INSERT INTO #Test VALUES ('Mon',7,'Lab3')
INSERT INTO #Test VALUES ('Tue',1,'Physics')
INSERT INTO #Test VALUES ('Tue',2,'Chemistry')
INSERT INTO #Test VALUES ('Tue',3,'Hindi')
INSERT INTO #Test VALUES ('Tue',4,'Physics')
INSERT INTO #Test VALUES ('Tue',5,'English')
INSERT INTO #Test VALUES ('Tue',6,'CS')
INSERT INTO #Test VALUES ('Tue',7,'Math')
SELECT
[Day],
MAX(CASE WHEN [Period] = 1 THEN [Subject] ELSE NULL END) AS P1,
MAX(CASE WHEN [Period] = 2 THEN [Subject] ELSE NULL END) AS P2,
MAX(CASE WHEN [Period] = 3 THEN [Subject] ELSE NULL END) AS P3,
MAX(CASE WHEN [Period] = 4 THEN [Subject] ELSE NULL END) AS P4,
MAX(CASE WHEN [Period] = 5 THEN [Subject] ELSE NULL END) AS P5,
MAX(CASE WHEN [Period] = 6 THEN [Subject] ELSE NULL END) AS P6,
MAX(CASE WHEN [Period] = 7 THEN [Subject] ELSE NULL END) AS P7
FROM
#Test
GROUP BY
[Day]
ORDER BY
CASE [Day]
WHEN 'Mon' THEN 1
WHEN 'Tue' THEN 2
WHEN 'Wed' THEN 3
WHEN 'Thu' THEN 4
WHEN 'Fri' THEN 5
WHEN 'Sat' THEN 6
WHEN 'Sun' THEN 7
ELSE 8
END
DROP TABLE #Test
Screenshot