Forum Discussion

Petter120's avatar
Petter120
Helper I
3 years ago

Parameter in MYSQL query is not working

Hi i have a MySQL query im trying to run from Power query editor and it usually work but this query has a parameter inside of it and its givning me an error:

SET @row_index := 1;

SET @row_index := -1;
SELECT DATUM,"FM" As Skift, Format(stddev(Duration),2) As STDEV, Format(avg(Duration),2) As Arimetric_Mean, (SELECT Format(AVG(subq.Duration),2) as median_value
FROM  (
    SELECT  s.DATUM, @row_index:=@row_index + 1 AS row_index, s.Duration
    FROM production_db.cykeltider_t as s
    WHERE s.LASTTID >= '2022-09-01 05:45:00' and s.LASTTID < '2022-09-01 15:00:00'  and s.OMRADE = "1022-08" 
    ORDER BY s.Duration) AS subq
  WHERE subq.row_index 
  IN (FLOOR(@row_index / 2) , CEIL(@row_index / 2))) as T

FROM production_db.cykeltider_t
WHERE LASTTID >= '2022-09-01 05:45:00' and LASTTID < '2022-09-01 15:00:00'  and OMRADE = "1022-08";

 

I am getting this error, an anyone assist me with this?

DataSource.Error: ODBC: ERROR [42000] [MySQL][ODBC 8.0(w) Driver][mysqld-8.0.28]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 'SELECT DATUM,"FM" As Skift, Duration, Duration
FROM production_db.cykeltider_t, ' at line 2
Information:
DataSourceKind=Odbc
DataSourcePath=dsn=MY_SQL
OdbcErrors=[Table]

 

Best regards 
Petter

3 Replies

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi Petter120 ,
    could this actually be an issue with the double quotes? They act as escape signs in Power Query.
    Couldn't you replace them with single quotes in your SQL-statement?

  • ImkeF's avatar
    ImkeF
    Community Champion

    Sorry, no further ideas from me here.