Ad hoc Contributed report

Ad hoc Contributed report

by Aditya Dubay -
Number of replies: 4

Hi,

I am using Moodle 3.8

When I try to run this report:

SELECT # h.id, # e.customint1, h.name AS Cohort, h.idnumber AS Cohortid,CASEWHEN h.visible =1THEN'Yes'ELSE'-'ENDAS Cohortvisible, CONCAT('<a target="_new" href="%%WWWROOT%%/course/view.php',CHAR(63),'id=',c.id,'">',c.fullname,'</a>')AS Course FROM prefix_cohort h JOIN prefix_enrol e ON h.id = e.customint1 JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% WHERE e.enrol ='cohort'AND e.roleid =5

It gives me this error:

"Error when executing the query: Error reading from database You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%FILTER_COURSES''.courseid%% WHERE e.enrol = 'cohort' AND e.roleid = 5 LIMIT 0' at line 13 SELECT # h.id, # e.customint1, h.name AS Cohort, h.idnumber AS Cohortid, CASE WHEN h.visible = 1 THEN 'Yes' ELSE '-' END AS Cohortvisible, CONCAT('',c.fullname,'') AS Course FROM mdl_cohort h JOIN mdl_enrol e ON h.id = e.customint1 JOIN mdl_course c ON c.id = e.courseid %%FILTER_COURSES?.courseid%% WHERE e.enrol = 'cohort' AND e.roleid = 5 LIMIT 0, 2 [array ( 0 => '', )]"

Average of ratings: -
In reply to Aditya Dubay

Re: Ad hoc Contributed report

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes - it's clearly bad SQL. That bit, '%%FILTER_COURSES:e.courseid%%' is just sitting there in the query. It doesn't make sense.

Where did you get this?
In reply to Aditya Dubay

Re: Ad hoc Contributed report

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
I would suggest to start small and then build up. For example:

SELECT h.name
FROM prefix_cohort h
Average of ratings: Useful (1)
In reply to Rick Jerz

Re: Ad hoc Contributed report

by Aditya Dubay -
Hi Howard
Hi Rick

Thanks for the reply.
Basically I want list of categories and courses with their associated cohorts.
Thats why I used that.
Can you suggest query which fulfil my requirements.

Thanks in advance smile
In reply to Aditya Dubay

Re: Ad hoc Contributed report

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Typically, one question leads to another when working with SQL.  It is best if you start exploring on your own so that you become more capable.

A good place to start is with this List of SQL Contributed reports.  What you seek might be there.