String functions cannot be used with the SQL-SELECT ORDER BY clause in Visual FoxPro (157188)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 6.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0
  • Microsoft Visual FoxPro 9.0 Professional Edition

This article was previously published under Q157188

SYMPTOMS

The following string functions cannot be used with the ORDER BY clause of the SQL-SELECT statement:
  • LEFT
  • RIGHT
  • SUBSTR
If you use the previous string functions with the ORDER BY clause, you receive the following error message:
SQL Column is not found
In Visual FoxPro 8.0 and in Visual FoxPro 9.0, you receive the following error message:
SQL ORDER BY clause is invalid.

CAUSE

ORDER BY supports only columns either by name or number, it does not support any other expressions.

WORKAROUND

Create a dummy column using the string function and then order by that column, as in the following example:
   SELECT *,LEFT(Prod_name,5) AS x FROM PRODUCTS ORDER BY x
				

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open Testdata database in the HOME()+"Samples\Data\" directory, for Visual FoxPro 6.0 goes to \\Program Files\Microsoft Visual Studio \Common\Samples\Data.
  2. Issue the following command:
          SELECT * FROM Products ORDER BY LEFT(Prod_name,5)

Modification Type:MajorLast Reviewed:3/18/2005
Keywords:KB157188 kbAudDeveloper