>Hi to all.
>
> Can i insert a function in SQL or select statement?
>
>e.g. select [field1], field[2], myfunction() from mydatabase ....
>
Not a problem, within certain limits. It's simply an expression whose return will be included in the resulting cursor or table. Realize that it will significantly impact performance, especially if the UDF() is used in a WHERE clause. I'd recommend using an AS clause in the SELCT so that you have a known name for the field resulting from the UDF (User-Defined Function):
SELECT SomeField, MyFunction() AS UDFResult FROM MyDataBase ...
This gives you a known name to reference the field by.
Some things to think about - the UDF needs to return the same data type in all cases, including when errors occur. If the UDF returns a number some of the time and a string at others, you're going to have a very confused VFP on your hands when the query executes. With things that can vary in size, like character strings, try to return things of a consistent length (and in numeric expressions, precision) from the UDF.
If your UDF performs any I/O against tables, make certain to restore the state of the VFP environment (data session, currently selected work area, record pointers, etc.) after the UDF completes - changing the VFP data environment on the fly can cause unexpected, and in most cases, undesirable things to happen.