This is the SQL equivalent of eval(my_string);
:
@Expression = 'SELECT "Hello, World!";';
PREPARE myquery FROM @Expression;
EXECUTE myquery;
Basically I combined the existing answers, neither tells you how to do eval exactly.
If you want to add parameters, you can use this:
@username = "test";
@password = "asdf";
@Expression = 'SELECT id FROM Users WHERE name = ? AND pass = ?;'
PREPARE myquery FROM @Expression;
EXECUTE myquery USING @username, @password;
And to answer the original question exactly:
@Expression = 'SELECT "Hello, World!";'
PREPARE myquery FROM @Expression;
INSERT INTO Results
EXECUTE myquery;
Note that the PREPARE ... FROM
statement wants a session variable (prefixed with @
). If you try to pass a normal variable, it will throw its hands up in the air and it just won't care.