Scenario: I am trying to set a string to a variable and then pass it to a prepared statement. I am using the "concat" function to create the string that will be passed.
Query:
set @floatvar := 'test1'
set @random_var2 := concat('SELECT ', @floatvar, ' AS Fields, COUNT(CASE WHEN ', @floatvar, ' IS NULL THEN 1 END) AS NullCount');
Obs: My query has more parts to be included in the string, but even with only this I am already having trouble, so I doing it step by step.
Issue: When I try to run this, I get a syntax error (SQL Error 1064) on line 2. I have no idea why this is happening.
Question: What is causing this issue, and how could it be fixed?
set @floatvar1 := 'test1'