Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Functions in a select
Message
De
25/08/2008 15:49:06
 
 
À
25/08/2008 15:25:12
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01341594
Message ID:
01341612
Vues:
19
The alternative would be to select into an empty field and then run the function afterward via a SCAN. Would that be preferable?

>There are two problems with your second example:
>1. You should specify field size when calling the function, e.g.
>select 0000+GetExpendituresBySubelement(elementnum) as expended
>2. Secondly, (more important) it is risky to change active work area within the function while running select-SQL, i.e. this code is not reliable.
>
>
>>This function
>>
>>function GetExpendituresBySubElement
>>lparameters lnSubElement
>>local lnOldWorkArea, lnRetVal
>>dimension lnRetval(1)
>>lnOldWorkArea = select(0)
>>
>>select  sum(amount) ;
>>from tip ;
>>inner join ledger on ledger.tip_id = tip.tip_id and source="RTA" ;
>>where val(substr(sponsor_id,5,2)) = lnSubelement;
>>into Array lnRetVal
>>
>>select(lnOldWorkArea)
>>return iif(isnull(lnRetVal),0,lnRetVal)
>>
>>seems to work OK when called with a single value like this
>>
>>? GetExpendituresBySubelement(2)
>>
>>But when embedded in another select like this
>>
>>select *, GetExpendituresBySubelement(elementnum) as expended ;
>>from rta_elements ;
>>order by elementnum
>>
>>I get only 0's and *'s. Can someone please explain?
>>
>>Thanks
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform