Answer the question
In order to leave comments, you need to log in
SQL Pivot is not working correctly, what am I doing wrong?
Hello,
SQL Pivot is not working as expected and I can't find the problem. Perhaps you can help.
Situation:
There is a database of, say, a questionnaire. The 3 columns I need are Person, Question and Answer (of course there are many more columns).
All this is stored in this form:
Person 1, Question 1, Answer to question 1
Person 1, Question 2, Answer to question 2
Person 1, Question 3, Answer to question 3
Person 2, Question 1, Answer to question 1
Person 2, Question 2, Answer to question 2
{ProcedureId, TokenValue, HtmlValue]
and so on.
Like this:
I am trying to modify a SQL query and display it in Excel 2007 (there is a need for this particular version, on others it is implemented simply with power query)
Select ProcedureId, [3_1_explain_alert_system_and_boosters_required], [1_1_patient_blacklist_checked]
FROM
(
select * from ProcedureStepsDetails
) As Temp
PIVOT
(
max([HtmlValue])
FOR [TokenValue] In([3_1_explain_alert_system_and_boosters_required], [1_1_patient_blacklist_checked])
) As pt
Человек * Вопрос 1 * Вопрос 2 * Вопрос 3
Человек1 Ответ 1 Ответ 2 Ответ 3
Человек2 Ответ 1 null Ответ 3
Человек * Вопрос 1 * Вопрос 2 * Вопрос 3
Человек1 Ответ 1 null null
Человек1 null null null
Человек1 null null Ответ 3
Человек1 null null null
Человек1 null null null
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question