Link to home
Start Free TrialLog in
Avatar of cswebdev
cswebdev

asked on

Fox query result to variable

in MS sql we can store a query result to a variable like :
declare @dt as datetime
select top 1 @dt = age from table

how can i do similar thing in Fox Pro Query. I am using Visual Fox Pro 9
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jrbbldr
jrbbldr

Just to follow on with Pavel's advice above...

SELECT TOP 1 Something ;
   FROM MyTable ;
   WHERE <some criteria>
   ORDER BY <some field sequence>
   INTO CURSOR Results

* --- Select Resultant Cursor, Then put first record into Variable ---
SELECT Results
Variable = Results.Something   && Where 'Something' represents a field such as Age

Good Luck

And don't forget to close the cursor :-)
You can write it as a function.

You send a table name and a field name.

You can get the value and return it to a calling procedure like this:
RETURN EVALUATE(FIELD(1))

Moreover, FoxPro has better ways for getting that:
CALCULATE MAX(field), MIN(field)  FOR condition TO nVariableMax, nVariableMin