Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select statement help
Message
From
04/03/2004 11:23:52
Erick Miranda
Formata Data Business - Grupo Linx
Contagem, Brazil
 
 
To
04/03/2004 10:08:35
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00883085
Message ID:
00883125
Views:
7
Hi Gary!


>I have two tables with almost identical fields.
>table A
>inv_cd chr(3)
>balance n(10,2)
>interest n(10.2)
>discount n(10,2)
>
>table B
>inv_cd chr(3)
>balance n(10,2)
>interest n(10.2)
>premium n(10,2)
>
>I need to create a select statement that will produce table C
>inv_cd chr(3)
>a.balance+b.balance as balance
>a.interest+b.interest as interest
>discount n(10,2)
>premium N(10,2)
>
>I need to accumilate like inv_cd's into one record.
>I hope I explained myself
>any help will be appreciated


Try this:
* Sum tableA
Select inv_cd, sum(balance) as balance, ;
   sum(interest) as interest, discount ;
  from tableA ;
  Group By inv_cd Into Cursor cursorA1

* Sum tableB
Select inv_cd, sum(balance) as balance, ;
   sum(interest) as interest, premium ;
  from tableB ;
  Group By inv_cd Into Cursor cursorB1

* Sum tableA + tableB
Select A.inv_cd, (A.balance + B.balance) as balance, ;
   A.discount, B.premium ;
  from cursorA1 A Inner Join cursorB1 B On A.invcd == B.invcd ;
  Group By inv_cd Into Cursor cursorC   && Would be Left Join
                                        && Would be Into Table tableC
I do 3 select's because I thinked that your tables can have more one record for each inv_cd.
I hope this help you.
Bye!
Erick
Força Sempre!
Strength Always!
Previous
Reply
Map
View

Click here to load this message in the networking platform