BUG: Update SQL Works Incorrectly with RAND() in WHERE ClauseID: Q139048 The information in this article applies to:
SYMPTOMSUsing the RAND() in an SQL UPDATE's WHERE clause can cause random results to occur.
CAUSEThe value of RAND() changes each time it is evaluated, unlike most FoxPro functions. FoxPro's internal SQL parser evaluates it once to do the Rushmore optimization and once more as each filter condition is tested for each record. This causes unpredictable, random results.
RESOLUTIONInstead of using the RAND() function in the WHERE clause, assign the value of the RAND() function to a memory variable. Then use the variable in the WHERE clause. For an example, please see the "Code to Correct Problem" section of this article. A new RAND() can be generated for every record tested in the filter by putting RAND() in a User Defined Function (UDF) and calling the UDF in the SQL command in place of RAND():
In this example the article's CAUSE section applies:
STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
Code to Reproduce ProblemThe following code illustrates the problem. If there wasn't a problem, the code should make 1000 updates to the table. Instead, the update fails either 999 or 1000 times.
Code to Correct ProblemTo fix the problem, remove the '*' from the updval line and substitute line would look like the following:
KBCategory: kbprg kbbuglist
KBSubcategory: FxprgSql vfoxwinbuglist3.00 buglist3.00b buglist5.00
Additional reference words: 5.00 3.00 3.00b inconsistent kbvfp300 kbvfp500
kbvfp600
|
Last Reviewed: August 10, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |