Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An easy way to use the same parameter value repeatedly in a query #104

Open
timhunt opened this issue Nov 19, 2021 · 0 comments
Open

An easy way to use the same parameter value repeatedly in a query #104

timhunt opened this issue Nov 19, 2021 · 0 comments

Comments

@timhunt
Copy link
Member

timhunt commented Nov 19, 2021

Sometimes, when writing a query, you want to use a single parameter value in several places. Each placeholder being used exactly once is a limitation of the Moodle database system, which we just use as-is, so there is no easy way to do this.

There are tricks you can do. For examle with a single query that joins serveral tables, you can include something like

JOIN (SELECT :my_value AS my_value) input ON 1 = 1

then you can refer to input.my_value everywhere. However, this is tricky to work out, and does not always work (e.g. with UNIONS).

In response to a question about this, I just relalised that we could implemented a work-around.

For example, we could make it that if you have parameters called :my_value, :my_value_copy1, :my_value_copy2, ..., then we only show a single input for 'my value' when someone runs the report, and then we duplicate that value as my_value_copy1, .... That should be feasible.

@timhunt timhunt changed the title Need an easy way to use the same parameter value repeatedly in a query An easy way to use the same parameter value repeatedly in a query Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant