I have a table like this:
CREATE TABLE MyDataTable
(
[RollNo] varchar(8),
[QuesBlock] int,
[RespVal] varchar(2)
);
INSERT INTO MyDataTable ([RollNo], [QuesBlock], [RespVal])
VALUES ('MBA0001', 1, A), ('MBA0001', 2, B), ('MBA0001', 3, D),
('MBA0002', 1, C), ('MBA0002', 2, A), ('MBA0002', 3, B),
('MBA0003', 1, B), ('MBA0003', 2, C), ('MBA0003', 3, A);
Therefore, my source data looks like this:
Now I want to reach a target table structure like this:
This is basically to tabulate the candidate-wise, question-wise responses for each question in an OMR-based test for a school. I have a fixed number of unique values (only 50) in the QuesBlock column, so I can live with hardcoding. I have gone through examples where pivot has been used to achieve something like this, but all of them have used aggregate functions like MAX, MIN, AVG etc. for working with numeric values. But in my case, the values of the RESPVAL column are all textual. How do I achieve this?