I have a SQL query which selects some values (and works across tables in the form of a join). One of the fields returns 0 or 1 but I want to return something else in the case of 0, or the case of 1 (yes/no).
The code:
SELECT Passed,
CASE Passed
WHEN '1' THEN 'Yes'
ELSE 'No'
END
FROM EXAM_INSTANCE
Works perfectly well.
But when I integrate this as a sub-query in the stored proc, I get the error:
Only one expression can be specified in the select list when the sub-query is not introduced with EXISTS.
The original query is:
select Firstname, Lastname, ei.Started,
((ei.totalcorrect*100)/@examQuestionCount) as percentage, passed, ei.InstanceID
from ea ei, INVITE i, OSTTable ost, f f
where ei.Finished is not null
and ei.InviteID = i.InviteID
I am trying:
select Firstname, Lastname, ei.Started,
((ei.totalcorrect*100)/@examQuestionCount) as percentage,
(SELECT Passed,
CASE Passed
WHEN '1' THEN 'Yes'
ELSE 'No'
END
FROM EA),
ei.InstanceID
from EA E ei, INVITE i, osttable ost, ef e
where ei.Finished is not null
and ei.InviteID = i.InviteID
What is the cause for my error?
PS I’ve changed table names for privacy reasons so don’t worry if they don’t match up.
1 Answer