Description of the differences between the MIN function and the MAX function and differences between the SELECT-SQL MIN field function and the MAX field function in FoxPro (98362)



The information in this article applies to:

  • Microsoft FoxPro for MS-DOS 2.0
  • Microsoft FoxPro for MS-DOS 2.5
  • Microsoft FoxPro for MS-DOS 2.5a
  • Microsoft FoxPro for MS-DOS 2.5b
  • Microsoft FoxPro for MS-DOS 2.6
  • Microsoft FoxPro for MS-DOS 2.6a
  • Microsoft FoxPro for Windows 2.5
  • Microsoft FoxPro for Windows 2.5a
  • Microsoft FoxPro for Windows 2.5b
  • Microsoft FoxPro for Windows 2.6
  • Microsoft FoxPro for Windows 2.6a
  • 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
  • Microsoft Visual FoxPro 9.0 Professional Edition

This article was previously published under Q98362

SUMMARY

There are distinct differences between the MIN() and MAX() functions and the SELECT-SQL MIN() and MAX() field functions. The SELECT-SQL MIN() and MAX() field functions accept only one argument, whereas the MIN() and MAX() functions accept multiple arguments.

The following examples demonstrate how each function would be used in a FoxPro program.
SELECT MIN(price) from detail
     && This statement will select the record with lowest price
     && in the database.

   SELECT MIN(IIF(price < 0,0,price)) FROM detail
     && This statement will select the record with the lowest price
     && as long as it is not less than zero; if it is less than zero,
     && it will return zero (0).

   ?MIN(54, 39, 40)
     && This statement will return the minimum of the three parameters
     && (39).

   ?MAX(54, 39, 40)
     && This statement will return the maximum of the three parameters
     && (54).

   SELECT MIN(price,0) from detail
     && This statement will cause the error " MISSING ) " to occur.
     && To correct this statement, remove the second argument from
     && the MIN() function, as shown in the first example.
		
For Visual FoxPro 6.0 and later versions, use this code:
open database home(2)+"data\testdata.dbc"
SELECT MIN(order_amt) from orders
     && This statement will select the record with lowest price
     && in the database.

   SELECT MIN(IIF(order_amt < 0,0,order_amt)) FROM orders
     && This statement will select the record with the lowest price
     && as long as it is not less than zero; if it is less than zero,
     && it will return zero (0).

   ?MIN(54, 39, 40)
     && This statement will return the minimum of the three parameters
     && (39).

   ?MAX(54, 39, 40)
     && This statement will return the maximum of the three parameters
     && (54).

   SELECT MIN(order_amt,0) from orders
     && This statement will cause the error " MISSING ) " to occur.
     && To correct this statement, remove the second argument from
     && the MIN() function, as shown in the first example.
		


Modification Type:MajorLast Reviewed:3/17/2005
Keywords:kbinfo KB98362