My goal is to create the following 2 Aging report formats:
Report As of 2/16/2005
(Date range is 8/1/2004 to 1/31/05)
Less Than 6 Months Old # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K
under 50K
------------------------------------------------------
(Date range is 7/31/2004 and prior)
6 Months Old Or Greater # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K
under 50K
------------------------------------------------------
I am processing a database and extracting records by Account Number. Each Account Number can have multiple records. Each record includes an Account Number, Date Lost field and a Stock field.
I need to create 1 summary record per account number and calculate the total dollar value of the Stock field. The
records need to be segregated by date into an Aging Report.
I compare the Date Lost field on the database records to the Report Date ranges to determine which report section the records are written to.
For ex: John Smith has the following records:
ACCTNUM DATELOST STOCKS
---------- ---------- ----------
12345 2004-09-01 30,000.00
12345 2004-09-01 20,000.00
12345 2004-09-01 10,000.00
---------
60,000.00
Joe Fields has the following records:
ACCTNUM DATELOST STOCKS
---------- ----------- ----------
23456 2002-07-01 4,000.00
23456 2002-07-01 5,000.00
23456 2002-07-01 1,000.00
----------
10,000.00
Report As of 2/16/2005
(Date range is 8/1/2004 to 1/31/05)
Less Than 6 Months Old # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K 1 60,000.00
under 50K
(Date range is 7/31/2004 and prior)
6 Months Old Or Greater # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K
under 50K 1 10,000.00
Would I use a SQL Union statement to generate the report totals and I was unsuccessful ?
I tried the following SQL statement but it will not work:
SELECT COUNT, SUM(STOCKS)
FROM CUSTOMERS AS C, PRODUCTS AS P
WHERE C.ACCTNUM = P.ACCTNUM AND DATELOST BETWEEN '2004-08-01' AND '2005-01-31'
GROUP BY ACCTNUM
UNION ALL
SELECT COUNT, SUM(STOCKS)
FROM CUSTOMERS AS C, PRODUCTS AS P
WHERE C.ACCTNUM = P.ACCTNUM AND DATELOST LESS THAN
'2005-01-31'
GROUP BY ACCTNUM
Report As of 2/16/2005
(Date range is 8/1/2004 to 1/31/05)
Less Than 6 Months Old # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K
under 50K
------------------------------------------------------
(Date range is 7/31/2004 and prior)
6 Months Old Or Greater # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K
under 50K
------------------------------------------------------
I am processing a database and extracting records by Account Number. Each Account Number can have multiple records. Each record includes an Account Number, Date Lost field and a Stock field.
I need to create 1 summary record per account number and calculate the total dollar value of the Stock field. The
records need to be segregated by date into an Aging Report.
I compare the Date Lost field on the database records to the Report Date ranges to determine which report section the records are written to.
For ex: John Smith has the following records:
ACCTNUM DATELOST STOCKS
---------- ---------- ----------
12345 2004-09-01 30,000.00
12345 2004-09-01 20,000.00
12345 2004-09-01 10,000.00
---------
60,000.00
Joe Fields has the following records:
ACCTNUM DATELOST STOCKS
---------- ----------- ----------
23456 2002-07-01 4,000.00
23456 2002-07-01 5,000.00
23456 2002-07-01 1,000.00
----------
10,000.00
Report As of 2/16/2005
(Date range is 8/1/2004 to 1/31/05)
Less Than 6 Months Old # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K 1 60,000.00
under 50K
(Date range is 7/31/2004 and prior)
6 Months Old Or Greater # of Accounts ACCT VALUE
------------------------- ------------- ----------
100K and Above
50 K up to less than 100K
under 50K 1 10,000.00
Would I use a SQL Union statement to generate the report totals and I was unsuccessful ?
I tried the following SQL statement but it will not work:
SELECT COUNT, SUM(STOCKS)
FROM CUSTOMERS AS C, PRODUCTS AS P
WHERE C.ACCTNUM = P.ACCTNUM AND DATELOST BETWEEN '2004-08-01' AND '2005-01-31'
GROUP BY ACCTNUM
UNION ALL
SELECT COUNT, SUM(STOCKS)
FROM CUSTOMERS AS C, PRODUCTS AS P
WHERE C.ACCTNUM = P.ACCTNUM AND DATELOST LESS THAN
'2005-01-31'
GROUP BY ACCTNUM