BUG: Problems with SET COLLATE and Queries with Integer Fields (176884)
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 5.0a
- Microsoft Visual FoxPro for Windows 6.0
- Microsoft Visual FoxPro for Macintosh 3.0b
This article was previously published under Q176884 SYMPTOMS
Queries in Visual FoxPro that compare integer fields in the WHERE clause of
a SQL Select statement between two or more tables may not return all
matching records. This problem occurs when the collation sequence is set to
anything but Machine.
RESOLUTION
The workaround to this problem depends on which version of Visual FoxPro is
being used. Four workarounds are listed below:
- Use the SET COLLATE command prior to running the query to set the
collation sequence to Machine. This works in all versions of Visual
FoxPro.
- Create an index on the integer fields before running the query. The
program in the Steps to Reproduce Behavior section can be modified to
accomplish this. All records will then be returned.
Follow each of the two CREATE CURSOR commands in the sample program with
a command to create an index on the integer field. A sample follows:
CREATE CURSOR t1 (in1 i)
INDEX ON in1 TAG in1
CREATE CURSOR t2 (in2 i)
INDEX ON in2 TAG in2
- Use numeric, float, or double type fields without decimal places instead
of integer fields although this may affect query performance. You will
need to test query speed if query performance is a concern. This
workaround works in all versions of Visual FoxPro.
- If you are using Visual FoxPro 5.0 or later, use the LEFT or RIGHT JOIN
syntax to join the tables rather than the WHERE clause.
For example, using the code from the Steps to Reproduce Behavior
section below, you can use the following queries to produce the correct
results. Keep in mind that the cursors created in the program below are
stripped down with only an integer field in each. The SELECT statements
below may produce very different results on real data although they
produce identical results on the test data:
SELECT * FROM t1 LEFT JOIN t2 ON t1.in1=t2.in2 INTO CURSOR t3
SELECT * FROM t1 RIGHT JOIN t2 ON t1.in1=t2.in2 INTO CURSOR t3
Either statement above can replace the following line in the sample
program below:
SELECT * FROM t1,t2 WHERE in1=in2 INTO CURSOR t3
- Unfortunately, the INNER JOIN syntax has the same problem as the SQL
Select statement with the WHERE clause.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
REFERENCES
For additional information, please see the following article in the
Microsoft Knowledge Base:
164869 SET COLLATE TO "GENERAL" May Affect Search Results
Modification Type: | Minor | Last Reviewed: | 3/14/2005 |
---|
Keywords: | kbbug kbpending KB176884 |
---|
|