Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Where Statement/ MySQL-Source

Noob Question:

I am trying  to use a WHERE Statement in a QV-Script with an ODBC-Connect to a MySQL-Server an a local qvw.

...

Let vmrD = Peek('modified_time', -1, 'statistics');

...

LOAD

id,

modified time

Field B,

Field C

FROM `db_main`.statistics

WHERE modified_time  >= $(vmrD);

...

But WHERE doesn't work with the given Data-Source [even if i ad (mq)] 😉

Is there an alternative way or a workaorund ?

1 Solution

Accepted Solutions
rbecher
MVP
MVP

Hi,

if field modified_time is a date/timestamp you shoud use MySql STR_TO_DATE function:

WHERE modified_time >= STR_TO_DATE('$(vmrD)','%Y-%m-%d %h:%i:%s');  -- if timestamp format is YYYY-MM-DD HH24:MI:SS

Please also take a look here:http://www.sqlines.com/mysql/functions/str_to_date

- Ralf

Astrato.io Head of R&D

View solution in original post

8 Replies
rustyfishbones
Master II
Master II

Try adding ` `

WHERE `modified_time` >= $(vmrD);

Anonymous
Not applicable
Author

Try you

LOAD

id,

modified time

Field B,

Field C

FROM `db_main`.statistics

WHERE modified_time  >= '$(vmrD)';

Bill_Britt
Former Employee
Former Employee

If you are running 11.20 SR4 there is an issue with Grave Accents `` you will need to user [ ] or "

Bill

Bill - Principal Technical Support Engineer at Qlik
To help users find verified answers, please don't forget to use the "Accept as Solution" button on any posts that helped you resolve your problem or question.
Clever_Anjos
Employee
Employee

I´m not seeing the

SQL SELECT command into your code

Do you have it?

rbecher
MVP
MVP

Hi,

if field modified_time is a date/timestamp you shoud use MySql STR_TO_DATE function:

WHERE modified_time >= STR_TO_DATE('$(vmrD)','%Y-%m-%d %h:%i:%s');  -- if timestamp format is YYYY-MM-DD HH24:MI:SS

Please also take a look here:http://www.sqlines.com/mysql/functions/str_to_date

- Ralf

Astrato.io Head of R&D
hic
Former Employee
Former Employee

You need to use a SQL SELECT if you want to connect to the database. A Load ... From will load from a file source, e.g. Excel.

HIC

Not applicable
Author

Is there a way to use  WHERE after the SQL-Connect? Something like:

SQL SELECT * FROM `db_main`.statistics

WHERE modified_time  >= $(vmrD);

or is it necessary to store the Tables in a file source first and LOAD (again) ?

11.20 SR3 x64

rbecher
MVP
MVP

Hi,

the Where Clause is part of the SQL statement against the database.

If field modified_time is a date/timestamp you shoud use MySql STR_TO_DATE function:

WHERE modified_time >= STR_TO_DATE('$(vmrD)','%Y-%m-%d %h:%i:%s');  -- if timestamp format is YYYY-MM-DD HH24:MI:SS 

- Ralf

Astrato.io Head of R&D