Problem with lookup code

I have simple piece of code where I need to select records based on some criteria:

SELECT RegionName, RegionName FROM regions ORDER BY RegionName WHERE Country={Country}

The {Country} refers to the screen variable on the same form

This code results however SQL runtime error
Error while accessing the database:
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 ‘WHERE Country=’ at line 1

(despite I use AJAX). It seems like {Country } is empty (despite is is selected from the dropdown list

any idea to fix this ?
Arthur

Yes. :slight_smile:

SELECT RegionName, RegionName FROM regions WHERE Country={Country} ORDER BY RegionName

The error is almost always before the quoted part of the statement.

I assume {Country} is integer otherwise is has to be quoted.

jsb

{Country} is a STRING()
I tried this

SELECT RegionName, RegionName FROM regions ORDER BY RegionName WHERE Country = '{Country}'

and this

SELECT RegionName, RegionName FROM regions ORDER BY RegionName WHERE Country = {'Country'}

and nothing seems to work ;-(

Try to fill a default value (blank or null) for {Country} in onLoad event.

{Country} = '';

SELECT RegionName, RegionName FROM regions WHERE Country={Country} ORDER BY RegionName

Rearrange the ORDER and WHERE some databases do not allow the ORDER BY before the WHERE

Resolved

rr - THANKS A LOT - your suggestion worked! WOHOO!