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;
Sagar Chaudhary
  • 1,343
  • 7
  • 21
  • 1
    Node.js mysql api is likely to be able to run a single statement. – Shadow Jan 07 '19 at 15:34
  • 1
    Not totally true @Shadow [node-mysql multiple statements in one query](https://stackoverflow.com/questions/23266854/node-mysql-multiple-statements-in-one-query) – Raymond Nijland Jan 07 '19 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. – Shadow Jan 07 '19 at 15:37
  • thanks @RaymondNijland – Sagar Chaudhary Jan 07 '19 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? – Raymond Nijland Jan 07 '19 at 16:09

0 Answers0