Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 2 Jahren
Letzter Beitrag:
vor 2 Jahren
Beteiligte Autoren:
Peter Hite, Fabrice Harari, Paulo Oliveira, DerekT

Referencing variables in a SQL statement

Startbeitrag von Peter Hite am 10.02.2016 00: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:
"Select * from clockinout where clockinout.storenum = gnThisStoreNum "
Nor does this:
"Select * from clockinout where clockinout.storenum = 'gnThisStoreNum' "


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

von Fabrice Harari - am 10.02.2016 00:51
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.

von Peter Hite - am 10.02.2016 03:20
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... :-)

von Fabrice Harari - am 10.02.2016 13:19

'when you change DB type, it automatically translates the sql language for the target DB'


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.

von DerekT - am 10.02.2016 13:44
Your problem is only in the generation of the select, just use:
"Select * from clockinout where clockinout.storenum ="+ gnThisStoreNum

von Paulo Oliveira - am 12.02.2016 17:44
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.