|
| Referencing variables in a SQL statement |
| Iniciado por guest, 10,feb. 2016 01:42 - 5 respuestas |
| |
| | | |
|
| |
| Publicado el 10,febrero 2016 - 01:42 |
I can't figure out how to reference global variables in a SQL statement. I have a table called clockinout with an int element called storenum. In the table I have many records with a storenum of 10. Using the following SQL works fine: "Select * from clockinout where clockinout.storenum = 10 " but the following does not: gnThisStoreNum=10 "Select * from clockinout where clockinout.storenum = gnThisStoreNum " Nor does this: "Select * from clockinout where clockinout.storenum = 'gnThisStoreNum' " |
| |
| |
| | | |
|
| | |
| |
| Publicado el 10,febrero 2016 - 01:51 |
Hi Peter,
1. You should use the query editor for that, it's much simpler
2. IF you -REALLY- want to write yor own sql code (and there are MANY reasons not to), then you have to understand that a SQL statement is simply a string, so the correct syntax is going to be: "Select * from clockinout where clockinout.storenum = "+gnThisStoreNum And the value of the global variable will be included in the string when this line is executed (NOT when the query is run, which can be much later
Best regards |
| |
| |
| | | |
|
| | |
| |
| Publicado el 10,febrero 2016 - 04:20 |
| Ahhh - thank you! Used to using it as a direct language. The query editor is a little cumbersome for simple sql statements, but it is nice. Thanks again. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 10,febrero 2016 - 14:19 |
Hi again
"nice" is not why you should use it. The reasons are: - when you use it and you change the analysis, it changes the queries for you automatically - when you use it, you have automatic completion in the code - when you change DB type, it automatically translates the sql language for the target DB - ...
And of course, the query editor creates queries that work without you having to think about it...  |
| |
| |
| | | |
|
| | |
| |
| Publicado el 10,febrero 2016 - 14:44 |
Fabrice
'when you change DB type, it automatically translates the sql language for the target DB'
really....
Define a calculated expression in the editor as 'Firstname+' '+Lastname' WD-HF loves it.
Change to MySql it fails - needs to be changed to CONCAT(Firstname' 'Lastname) There are quite a few cases where using native WD-HF does not run in other databases especially if you use the WL operators. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 12,febrero 2016 - 18:44 |
Your problem is only in the generation of the select, just use: "Select * from clockinout where clockinout.storenum ="+ gnThisStoreNum |
| |
| |
| | | |
|
| | | | |
| | |
|