Question : Query with "If" condition

Hi there,

Suppose I have a query with 3 fields, with the following values (as examples):

Question ID    Type                  Answer     Alternative
1                           1                      4                        D  
2                           1                      3                        C
3                           2                 0.032              (nothing)

I would like to create one last field (a 5th one), named (say) "AnswerShown" where it gets Alternative if Type is 1, and it gets Answer if Type is 2...

Please answer showing how to modify the SQL query statement given below...

Thanks!

SELECT Questoes.QuestaoID, Questoes.QuestaoTipo AS Type, Questoes.QuestaoResposta AS Answer, Respostas.Resposta AS Alternative
FROM Questoes LEFT JOIN Respostas ON Questoes.QuestaoResposta = Respostas.RespostaID;

Answer : Query with "If" condition

what about this:
1:
2:
SELECT Questoes.QuestaoID, Questoes.QuestaoTipo AS Type, Questoes.QuestaoResposta AS Answer, Respostas.Resposta AS Alternative, IIF(Type=1, Alternative, Answer) AnswerShown
FROM Questoes LEFT JOIN Respostas ON Questoes.QuestaoResposta = Respostas.RespostaID;
Random Solutions  
 
programming4us programming4us