Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Union, Group By and Sum question
Message
From
13/01/2001 18:10:50
Cindy Winegarden
Duke University Medical Center
Durham, North Carolina, United States
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00463430
Message ID:
00463443
Views:
14
Brenda,

You have the following code which creates a CURSOR, not a "record,", except that you want to know where to specify the CURSOR's name right?

If you want the SUM() of your last 3 columns, you will probably need a second SQL, and even if it could be done in one step, two steps will be easier to understand. UNION's take their column names from the first statement.

The *'s are because SQL determines the size/number of decimal places of a resulting field by the first value it sees. If one of your subsequent values is more than x.xx places you will get the *'s. To get around this use PAD functions for character values, and add or multiply 0's for numerics and $0's for currency.

Assuming I have read you right you need:
SELECT CustNo, Disb_rt_no, Disb_ddaNo, ;
  DisbddAmt + $0000.00 AS DisbddAmt, ;
  $0000.00 AS Prin_pmt, $0000.00 AS Int_pmt ;
  FROM Disb_dda ;
  UNION ALL ;
  SELECT CustNo, Pmt_rt_no, Pmt_dda_no, ;
  $0000.00 AS DisbddAmt, ;
  Prin_pmt, Int_pmt ;
  FROM Payment ;
  INTO CURSOR Temp1 

SELECT CustNo, Disb_rt_no, Disb_ddaNo, ;
  SUM(DisbDdAmt) AS Total_DisbDdAmt, ;
  SUM(Prin_pmt) AS Total_Payments, ;
  SUM(Int_pmt) AS Total_Interest ;
  FROM Temp1 ;
  INTO CURSOR Temp2 ;
  GROUP BY CustNo, Disb_rt_no, Disb_ddaNo
>I have the following UNION ALL SQL which creates a record that contains fields from two other tables. Now I want unique custno, column2, column3, and sum on column4, column5 and column6. In the UNION ALL I could not see how to say "INTO" so that I could assign a cursor name. Also, my Union All fields had some '**' in some columns. What are the astericks?
>
>Select custno, disb_rt_no, disb_ddano, disb_dda.disbddaamt, ;
>0.00, 0.00 From disb_dda ;
>Union All ;
>Select custno, pmt_rt_no, pmt_dda_no, 0.00, prin_pmt, int_pmt From payment
Previous
Reply
Map
View

Click here to load this message in the networking platform