moodleou/moodle-report_customsql

Ability to use parameters in the midst of a text pull.

mwilday opened this issue · 3 comments

We'd like to be able to enter a parameter in the midst of SQL statement but are having difficulty doing it.

AND prefix_category_path = '/ :parameter/' but the query keeps failing. Is this possible? Am I just not sure how to do it?

Parameter values are not just added to the query using string search and replace. They need to take the place of a single value in the SQL. So, to add them in the middle of a string, you need to use concatenation:

AND prefix_category_path = CONCAT('/', :parameter, '/')

This is not a bug. Closing.

Parameter values are not just added to the query using string search and replace. They need to take the place of a single value in the SQL. So, to add them in the middle of a string, you need to use concatenation:

AND prefix_category_path = CONCAT('/', :parameter, '/')

Thank you, this is incredibly helpful!!!