Azure SQL Database
An Azure relational database service.
5,844 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Team,
I want to write a query for my input table and add a additional column on fly if parent question response satisfy the condition mentioned in the child question. Below is sample result that I want to achieve.
Please help.
Try something like this:
select Q.*,
case when P.QuestionId is null then 'Y'
else
case Q.Condition
when '=' then iif(P.QuestionResponse = Q.ParentResponse, 'Y', 'N')
when '>' then iif(P.QuestionResponse > Q.ParentResponse, 'Y', 'N')
end
end as ShowQuestion
from Questions Q
left join Questions P on P.QuestionId = Q.ParentQuestionId
It can be extended for more supported conditions.