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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Count with condition Queries 6
if 3*15 5
Writing UDF Help 4
Add description to UDF argument 1
How do I create and save a new function in Excel? 1
C++ dll in C# 7
Help with Union 2
average(if not working properly 7

Back
Top