Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foxpro where expression invalid?

lcVillkor1 = "table.numbers > 1"

SELECT * FROM table WHERE lcVillkor1 ORDER BY table.numbers

I got the error - SQL: WHERE clause is invalid.

I've tried almost every possible combination

"table.numbers > 1", (table.numbers > 1), "(table.numbers > '1')" etc..

Im trying to get some posts (where a number is greater then 1) from a table to print out.

like image 680
Rob Avatar asked Nov 30 '25 15:11

Rob


2 Answers

Use & before the variable to expand it:

lcVillkor1 = "table.numbers > 1"

SELECT * FROM table WHERE &lcVillkor1 ORDER BY table.numbers
like image 141
pmoleri Avatar answered Dec 03 '25 05:12

pmoleri


You can't just put a variable name in a line of code and have it execute. Instead, build up your SQL command as a text variable, and then use something like macro substitution to execute it:

lcVillkor1 = "table.numbers > 1" 
lcSql = "SELECT * FROM table WHERE " + lcVillkor1 + " ORDER BY table.numbers"
&lcSql

Also, for future reference, perhaps table and field names close to reserved words - eg "table" and "numbers" - may not be ideal.

like image 34
kevinw Avatar answered Dec 03 '25 06:12

kevinw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!