Because of how Moodle database query system works, you cannot use either a : or ? in they query. For convenience you can use %%C%% and %%Q%% in strings, and they will get replaced with : and ? in the results.
Also, you don't need to generate HTML. That won't work (it will get escaped). Instead, have two columns in your query:
SELECT fullname AS course,
CONCT('%%WWWROOT%%/course/view.php%%Q%%id=', c.id) AS course_link_url,
and in the results that will be turned into one column that is a link.
Finally, if you use this report, take a minute to read the text on-screen as part of the edit query form. It explains these tips and more.
Also, you don't need to generate HTML. That won't work (it will get escaped). Instead, have two columns in your query:
SELECT fullname AS course,
CONCT('%%WWWROOT%%/course/view.php%%Q%%id=', c.id) AS course_link_url,
and in the results that will be turned into one column that is a link.
Finally, if you use this report, take a minute to read the text on-screen as part of the edit query form. It explains these tips and more.