Forum Discussion
Use a parameter in a query in a MySQL database
- 9 years ago
Hi
because tx_id is a series of id numbers you need to pass them into SQL in a format it expects.
I used Text.Combine to create my parameter so it read '123','124','125' which is what i needed to pass to the SQL where clause. As you are using a number then i do not think you need the '' so you need to pass into SQL IN clause (123,123,123,123) etc if tx_id looks like 123,123,123,123 then you can concatenate it into your SQL like your example.
So the key to solving this is to make sure that tx_id results look exactly what SQL requires.
Regards
Mike
what is your error?
- alicia579 years agoHelper I
If I write "... where id in @tx_id" the error is "MySQL: Fatal error encountered during command execution."
Otherwise
the error is "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 '@'tx_id'' at line 13
I suppose it is a syntax error because when I replace the condition by "where id in (1,2)" I obtain results I am expecting.
I have also tried to modify the query directly in the Advanced Editor :
"let
dbQuery="select ... from ... where id in" & @tx_id,
Source = MySQL.Database("server", "name_database", [Query=dbQuery, CommandTimeout=#duration(0, 16, 40, 0), ReturnSingleDatabase=true])
in
Source"but I have no result.
- alicia579 years agoHelper I
Nobody would have an idea ? :catsad:
- mmanwaring9 years agoResolver I
Hello Alicia
I have got this to work by concatenating my parameter into the SQL
for example
where id = ' "& Parameter &" '
just be sure to drill down in power query so that your parameter is a single value. if you need multiple id then this will be different to create.
thanks
Mike
- alicia579 years agoHelper I
Hello mmanwaring,
Thank you very much for your answer !
Indeed I need a list of id. Do you know what is the way to create it ?
Regards,
Alicia