No, it's not a bug. When you reference field alias that has the same name as field name, the field name takes precedence. IOW, in your query 'ORDER BY sales' references field 'sales' from 'saleshist' table which isn't present in the query field list.
>The VFP 9 Help says the following re 9.0 SQL enhancements:
>
>A SELECT … DISTINCT … ORDER BY command will generate an error if the specified ORDER BY field is not in the SELECT field list.
>
>However the followig sql statement generates a "SQL: Order By clause is invalid" error:
>
>SELECT DISTINCT (Sales / 10) as sales FROM saleshist INTO CURSOR test ORDER BY sales
>
>Setting EngineBehavior 80 gets rid of the error condition.
>
>Is is a Bug ?
>
>A work around is:
>
>SELECT DISTINCT (Sales / 10) as Sales1 FROM saleshist INTO CURSOR test ORDER BY sales1
>
>but the workaround is a pain.
--sb--