Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How inserting function in SQL???
Message
From
17/03/1999 09:18:06
 
 
To
17/03/1999 08:59:12
Larry Santos
Local Data System
Philippines
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00198513
Message ID:
00198522
Views:
13
>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.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform