In the query you produce you need to name the inner query like this:
SELECT ...
FROM (
...
) x
GROUP BY CourseName,GL_Course.StartDate
The inner query needs to have an alias even if you don't reference it explicitly in the outer query.
Edit
In your code you need to change this:
set @fromClause = ' from (' + @sqlInner + ') x'