How we can group the result of the query depending up on the parameter passed.
A small stored procedure is shown below. parameter Param is passed to the procedure.
If param value is “f” the result must group by starttime otherwise by using formid. How can i do this. ???I tried the code show below but its not working .
DROP PROCEDURE IF EXISTS Test;
CREATE PROCEDURE Test (Param VARCHAR (2))
BEGIN
SELECT formid, starttime
FROM tbevaluationscoreinfo
CASE Param
when 'F'
then group by starttime;
else
group by formid;
end
END;
One way is to move branching up a level:
Another, less recommended solution, is dynamic SQL.
And the third possible solution is: