Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Functions in a select
Message
From
25/08/2008 17:03:15
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
25/08/2008 15:17:40
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01341594
Message ID:
01341636
Views:
15
>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

You could prevent that using a cast. However calling such a function wouldn't be feasible. Instead youı might do somethging like:
select rta_elements.*, cast(nvl(tmp.amount,0) as y) as expended ;
  from rta_elements ;
  left join ;
  (select  cast(val(substr(sponsor_id,5,2)) as int) as sponsor_id, sum(amount) as amount ;
     from tip ;
         inner join ledger on ledger.tip_id = tip.tip_id and source="RTA" ;
         group by 1) tmp ;
  on tmp.sponsor_id = rta_elements.elementnum ;
  order by elementnum
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform