0

I have a mysql query which runs fine on workbench.
But it gives error when i try to execute it in nodejs where i am using npm module mysql.
I have tried using backticks but to no help.

sqlMessage:"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 'SET @PivotQuery = CONCAT('SELECT Country,', @PivotQuery, ' FROM TestEmployee GRO' at line 1"

SELECT GROUP_CONCAT(CONCAT(' MAX(IF(State= ''',t.State,''', Salary, NULL)) AS ',t.State)) INTO @PivotQuery FROM  (SELECT State FROM TestEmployee GROUP BY State) t; SET @PivotQuery = CONCAT('SELECT Country,', @PivotQuery, ' FROM TestEmployee GROUP BY Country'); PREPARE statement FROM @PivotQuery; EXECUTE statement; DEALLOCATE PREPARE statement;
5
  • 1
    Node.js mysql api is likely to be able to run a single statement. Commented Jan 7, 2019 at 15:34
  • 1
    Not totally true @Shadow node-mysql multiple statements in one query Commented Jan 7, 2019 at 15:35
  • 2
    @RaymondNijland it is totally true, as you also found in the duplicate topic, multi sql statement execution in disabled by default. Commented Jan 7, 2019 at 15:37
  • thanks @RaymondNijland Commented Jan 7, 2019 at 16:02
  • maybe i misread/underunderstood your first comment @Shadow i readed more or less "node.js mysql api can only run one statement"... That's why i said not totally true because Node.js mysql api is prefect able to execute multiple statements just fine when enabled like you said in your last comment .. "multi sql statement execution in disabled by default" i already knew that why do you think i posted the duplication link? Commented Jan 7, 2019 at 16:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.