I have the following table DDL:
CREATE TABLE [dbo].[Test] (
[UserId] NVARCHAR (128) NOT NULL,
[TestId] INT IDENTITY (1, 1) NOT NULL,
[ExamId] INT NOT NULL,
[Title] NVARCHAR (100) NULL,
[Status] INT NOT NULL,
[CurrentQuestion] INT DEFAULT ((999)) NOT NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED ([TestId] ASC)
);
This table contains:
- A list of ALL Exams and Tests that are available. These rows have a UserId = 0
- A list of Exam and Test that are in progress for a particular user (UserId != 0)
- A user may have one or may have multiple rows in this table.
Is there a way that I can create a view that shows a list of all the tests and where it exists the additional information for a user if that user has started a test. I'm really not sure if this needs to be a view or a stored procedure as it would need to take as input a UserId.
For the UserId = 1
who in this example has started two of the available tests:
ExamId TestId Title Status
1 1 Exam1Test1 Started
1 2 Exam1Test2
2 3 Exam1Test3 Started
2 4 Exam1Test4
or for the UserId = 2
who in this example has started three of the available tests:
1 1 Exam1Test1 Started
1 2 Exam1Test2
2 3 Exam1Test3 Started
2 4 Exam1Test4 Started