You receive the "SQL expression too complex" error message if the IN clause includes more than 25 values in FoxPro (103031)



The information in this article applies to:

  • Microsoft FoxPro for Windows 2.5
  • Microsoft FoxPro for Windows 2.5a
  • Microsoft FoxPro for MS-DOS 2.0
  • Microsoft FoxPro for MS-DOS 2.5
  • Microsoft FoxPro for MS-DOS 2.5a
  • 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 5.0a
  • Microsoft Visual FoxPro for Windows 6.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0

This article was previously published under Q103031

SYMPTOMS

The "SQL expression too complex" error message appears if you have used 25 or more values in the IN clause of the SELECT-SQL command.

CAUSE

The maximum number of values is 24 that you can include in the IN clause.

Note Microsoft Visual FoxPro 9.0 removes the limit of 24 values in the IN (Value_Set) clause for the WHERE clause. However, the number of values remains subject to the setting of "SYS(3055) - FOR and WHERE Clause Complexity."

RESOLUTION

See the "More Information" section for an example of the problem and a workaround.

MORE INFORMATION

Steps to Reproduce Problem

FoxPro 2.0, 2.5, or 2.6
  1. Use the Customer.dbf table in the Tutorial directory.
  2. Issue the following SELECT-SQL command:
    Select * from customer where cno in;
    ('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',;
    '16','17','18','19','20','21','22','23','24','25')
    					
    The "SQL expression too complex" error message appears.
Visual FoxPro 3.0, 5.0, 6.0
  1. Use the Customer.dbf table. In Visual FoxPro 3.0 and 5.0, Customer.dbf is located in the Samples\Data folder. In Visual FoxPro 6.0 and later, use this command:
    USE HOME(2)+"data\customer.dbf"
    					
  2. Issue the following SELECT-SQL command:
    Select * from customer where cust_id in;
    ('ALFKI','ANATR','ANTON','AROUT','BERGS','BLAUS','BLONP','BOLID','BONAP','BOTTM',;
       'BSBEV','CACTU','CENTC','CHOPS','COMMI','CONSH','DRACD','DUMON','EASTC','ERNSH',;
       'FAMIA','FISSA','FOLIG','FOLKO','FRANK')
    The "SQL expression too complex" error message appears.

Workaround

  1. In FoxPro 2.x, create a temporary table with one field in it called CNO. In Visual FoxPro, name the field Cust_id. The Temp table should contain the values in the CNO or Cust_id field that you want to find in the Customer table.
  2. Issue one of the following SELECT-SQL commands depending on your version of FoxPro:
    ** For FoxPro 2.x use this line
    Select * from customer where cno in (select cno from temp)
    
    ** For Visual FoxPro, use this line
    Select * from customer where cust_id in (select cust_id from temp)
    					

Modification Type:MajorLast Reviewed:3/10/2005
Keywords:KB103031 kbAudDeveloper