1

I have an application called Moodle version 1.9 and was migrated from Windows platform and Microsoft SQL Server to Linux and MySQL.

Now, when I click save changes the SQL query statement from Custom SQL, it gives me "Query failed".

I would appreciate your help to advise how to fix the below SQL statement that I got from http://docs.moodle.org/22/en/ad-hoc_contributed_reports#All_Ungraded_Assignments_w.2F_Link

SELECT 
    u.firstname AS "First",
    u.lastname AS "Last",
    c.fullname AS "Course",
    a.name AS "Assignment",
    '<a href="http://moodle.domain.com/mod/assignment/submissions.php' + char(63) +
        + 'id=' + cast(cm.id AS varchar) + '&userid=' + cast(u.id AS varchar) +
        + '&mode=single&filter=0&offset=2">' + a.name + '</a>'
        AS "Assignmentlink"
FROM prefix_assignment_submissions AS asb
    JOIN prefix_assignment AS a ON a.id = asb.assignment
    JOIN prefix_user AS u ON u.id = asb.userid
    JOIN prefix_course AS c ON c.id = a.course
    JOIN prefix_course_modules AS cm ON c.id = cm.course
WHERE asb.grade < 0 
    AND cm.instance = a.id 
    AND cm.module = 1
ORDER BY c.fullname, a.name, u.lastname
3

you should use concat to join strings.

this column:

'<a href="http://moodle.domain.com/mod/assignment/submissions.php' + char(63) +
+ 'id=' + cast(cm.id AS varchar) + '&userid=' + cast(u.id AS varchar) +
+ '&mode=single&filter=0&offset=2">' + a.name + '</a>'
AS "Assignmentlink"

in mysql should write as this:

concat('<a href="http://moodle.domain.com/mod/assignment/submissions.php',char(63) , 'id=' , cast(cm.id AS varchar) , '&userid=' , cast(u.id AS varchar)  , '&mode=single&filter=0&offset=2">' , a.name , '</a>')
AS "Assignmentlink"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.