How to use Parameters in functions

X

xyz_db_jim

I want a parameter to capture the field name, and then use the /parameter as
an argument to a function. I can't figure out the syntax.

PARAMETERS fField Text;

SELECT Max(fField) as MaxValue
FROM myTable;

If I enter "Age" as the field, the query returns Age as the value in
MaxValue, where I wanted the Max of the Age field, not the string.

What's the magic voodoo syntax to pull this off.

Thanks
Jim
 
G

Gerald Stanley

One way that could do this is to use the Switch function to check fField
against the name of each column in the table e.g.

PARAMETERS fField Text;
SELECT Switch(fField = 'col1', Max(col1), fField = 'col2', Max(col2), fField
= 'col3' , Max(col3) etc) As MaxValue
FROM YourTable

Hope This Helps
Gerald Stanley MCSD
 
D

Dulce

To create a paramenter, first you need to add a new field name Age. After
you have enter Field Age, you will need to use a paramenter box name [Max
Age?:].

I hope this helps
Dulce
 
Top