Article ID: 133001
Article Last Modified on 12/3/2003
* start of SQLUDF.PRG
*
* This program selects records from the input table and calculates a
* running total in the output table by using a UDF.
nRunningTot = 0 && initialize running total to 0
nIterations = 0 && initialize iteration counter to 0
SELECT *, Add_Em(nField1) as nRunTotal FROM SQLUDF INTO CURSOR temp
BROWSE NOWAIT
PROCEDURE Add_Em
PARAMETERS tnFld1
nIterations = nIterations + 1 && Increment iteration counter
WAIT WINDOW "Record Number: "+ALLTRIM(STR(RECNO())) + ;
CHR(13)+ "Number of Iterations: "+ALLTRIM(STR(nIterations)) ;
TIMEOUT 1
nRunningTot=nRunningTot + tnFld1 && Calculate running total
RETURN nRunningTot
ENDPROCEDURE
*End of SQLUDF.PRG
* start of SQLUDF2.PRG
*
* This program sets a logical flag to test for the first iteration of
* the UDF to suppress getting a sum from the first record twice.
*
nRunningTot = 0 && initialize running total to 0
nIterations = 0 && initialize iteration counter to 0
lFirst_Time = .T. && initialize 1st time through variable
SELECT *, Add_Em(nField1) as nRunTotal FROM SQLUDF INTO CURSOR temp
BROWSE NOWAIT
PROCEDURE Add_Em
PARAMETERS tnFld1
IF lFirst_Time != .T. && Only run if not 1st time through
nIterations=nIterations + 1 && Increment iteration counter
WAIT WINDOW "Record Number: " + ;
ALLTRIM(STR(RECNO())) + ;
CHR(13) +"Number of Iterations: " + ALLTRIM(STR(nIterations));
TIMEOUT 1
nRunningTot = nRunningTot + tnFld1 && Calculate running total
ENDIF
lFirst_Time=.F. && Togggle to .F. on 1st call to UDF
RETURN nRunningTot
ENDPROCEDURE
*End of SQLUDF.PRG
124402 Calling a User-Defined Function (UDF) from SQL SELECT
Additional query words: VFoxWin FoxMac FoxDos FoxWin
Keywords: KB133001