Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Functions in a select
Message
 
 
To
25/08/2008 18:55:38
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01341594
Message ID:
01341669
Views:
10
>>>>This is exactly what I gave you in one of my messages as well.
>>>>
>>>>Re: Functions in a select Thread #1341594 Message #1341631
>>>
>>>Almost but not quite. Cetin's works, your doesn't. Note the difference in the last ON clause.
>>>
>>>Thanks for your help anyway. I still learned something from the discussion.
>>
>>I see no difference except for CAST as Integer. That may be a good point, actually.
>>
>>cast(val(substr(sponsor_id,5,2)) as int)
>
>Here is your code
>select R.*, CAST(NVL(Expended,0) as I) as expended from rta_elements R LEFT JOIN
>(   select  sum(amount) as Expended, val(substr(MyAmount.sponsor_id,5,2))  as GroupID ;
>from tip ;
>inner join ledger on ledger.tip_id = tip.tip_id and source="RTA" ;
>group by 2) MyAmount ON R.ElementNum = myAmount.GroupID
>
>Here is Cetin's
>
>select rta_elements.*, cast(nvl(tmp.amount,0) as int)/1000 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
>
>
>Yours says: ON R.ElementNum = myAmount.GroupID
>his on tmp.sponsor_id = rta_elements.elementnum
>
>note that you reference the derived table 'MyAmount' inside the select which creates it. This throws an error that says field MyAmount does not exist..

I see, that was just a typo, of course. BTW, why does he divide by 1000? Other than that I still don't see a difference.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform