Max

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Is there a function to get the max of different fields for
a record?

For example, a table looks like

ID number1 number2 number3...
1 20 15 13

I need a function to return 20, the largest of 20,15,13.

Thanks for any help.

Chris
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I replied to a similar Q in the past few days. Your query will have
to call a user-defined function that will get the max number. E.g.:

SELECT ID, Greatest(number1, number2, number3) As Mostest
FROM TableName

Put this function in a standard module:

Public Function Greatest(ParamArray var() As Variant) As Variant

Dim max As Variant
Dim i As Integer

' Initialize
max = var(LBound(var))
For i = LBound(var) to UBound(var)
If var(i) > max Then max = var(i)
Next i

Greatest = max

End Function


MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQCQliIechKqOuFEgEQJdewCg1NIvp7FmF15uUem9hZDm2mdAzmsAoJKF
fWFPvXdetoNmuWReJJn2wJ5a
=S62R
-----END PGP SIGNATURE-----
 
Back
Top