I have 3 tables in a database, 1 been a yoga class, another been the members and an intersection between them, I want to create a stored procedure that will print the details of a specified class and each member's name and contact number assigned to the class. The reports output should have the same format as:
YOGA CLASS REPORT:
___________________
Class ID: 1112
Week day: Monday [Time: 07:00:00]
Studio Number: 1
No. Member Name Contact Number
________________________________________
1 John Doe +26 83 562 3953
So far I have:
CREATE PROCEDURE sp_Report
@classID SMALLINT
AS
IF NOT EXISTS(SELECT * FROM class WHERE classID = @classID)
BEGIN
RAISERROR ('classID does not exist',16,1)
RETURN
END
DECLARE @classWeekday VARCHAR(15)
DECLARE @classTime TIME
DECLARE @classStudioNo TINYINT
SELECT @classWeekday = class.classWeekday, @classTime = class.classTime,
@classStudioNo = class.classStudioNo
FROM class
WHERE @classID = classID
PRINT 'YOGA CLASS REPORT'
PRINT 'Class code:' +CAST(@classID AS VARCHAR)
PRINT 'Week day:' +@classWeekday +'[Time:' + CAST(@classTime AS VARCHAR)+ ']'
PRINT 'Studio Number' +CAST(@classStudioNo AS VARCHAR)
How do I now print all the members that attend a specific class ? any help will greatly appreciated thanks.