Solved

summing up fields from access arranged by date....

Posted on 2002-04-24
8
165 Views
Last Modified: 2013-12-24
okay i have the following MS Access database table:


table name: order_items
fields:
  Field Name        Data Type
  ----------        ---------
  id                AutoNumber
  frn_order_id      Number
  frn_product_ID    Text
  quantity          Number
  price             Number (format is "Currency")
  dateoforder       Date/Time  
  localdealer       Text


here's is what i want to do with it:


i want to be able to output the following information:



**********************************************************
Current Month: April

Dealer               |      SalesTotal          
-------------               ----------          
d001                         $1504.15          
d002                         $1104.19          
d003                         $1042.34          
d004                         $1704.88          
d005                         $1796.01          
.                            .
.                            .
.                    .
**********************************************************


where "Dealer" is the value of the "localdealer" field, and "SalesTotal" is the SUM of the values in the "price" field for that corresponding dealer.
and also the records should be organized by month (i.e "Current Month")
by using the "dateoforder" field.
(If it's easier to list the month as 04/02, that's okay)  



and also need to output this....

*****************************************************
ProdID   Quant      Price      Date                STotal
------   -----      -----      ----                ------
101        2        $1.00      4/07/02 5:00:32 PM  $2.00
107        5        $6.25      4/09/02 5:00:32 PM  $31.25
107        1        $10.25     4/11/02 5:00:32 PM  $10.25
.          .        .          .                   .
.          .        .          .                   .
.          .        .          .                   .
---------------------------------------------------------                                     (TOTAL)

**********************************************************

where "ProdID" is the value of the "frn_product_ID" field, "Quant" is the value of the "quantity" field, "Price" is the value of the "price" field, "Date" is the value of the "dateoforder" field, "STotal" is the (quantity field x price field),
and "TOTAL" is the sum of all the "STotal" fields.


hope someone can figure this out..
0
Comment
Question by:sagardeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:sagardeo
ID: 6966309
sorry about the bad spacing in the display, i spaced it correctly in my posting but showed up different. still is readable though.
0
 
LVL 1

Expert Comment

by:ndintenfass
ID: 6967155
For the first one, you should be able to do this in SQL.  Your CFQUERY would look something like:


SELECT localdealer,sum(price*quantity) as SalesTotal
FROM order_items
WHERE month(dateoforder) = #month(now())#
GROUP BY localdealer


You can then just build a simple HTML table using CFOUTPUT.  Do you need help with that part of it?

Or, if you need all months, but want to group by month, you could do something like:

SELECT localdealer,year(dateoforder) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoforder),month(dateoforder)
ORDER BY year(dateoforder) desc, month(dateoforder) desc

Then, use the GROUP attribute on your CFOUTPUT on the month column -- you can then output a report for each month per dealer.

Make sense?

As for the second thing -- you can either do the STotal sum in your SQL (similar to above), or just do the math as you render your output in CF.  You can add up the TOTAL as you loop over the records.  It might look something like:

<cfquery name="getOrders" datasource="YourDSN">
SELECT frn_product_id,quantity, price,dateoforder
FROM order_items
</cfquery>

<table border=1>
<tr>
<td>ProdID</td>
<td>Quant</td>  
<td>Price</td>
<td>Date</td>          
<td>STotal</td>
</tr>
<cfset total = 0>
<cfoutput query="getOrders">
<tr>
<td>#frn_product_id#</td>
<td>#quantity#</td>  
<td>#dollarFormat(price)#</td>
<td>#dateFormat(dateoforder,"m/dd/yy")# #timeFormat(dateoforder,"h:mm:ss tt")#</td>  
<cfset stotal = price * quantity>
<cfset total = total + stotal>      
<td>#dollarFormat(stotal)#</td>
</tr>
</cfoutput>
<tr>
<td colspan="4"></td>
<cfoutput><td>#dollarFormat(Total)#</td></cfoutput>
</tr>
</table>
0
 

Author Comment

by:sagardeo
ID: 6969806
did you mean to say "use the GROUP attribute on your CFOUTPUT on the localdealer column - you can then output....?

when i group on the month column in the cfoutput,
it only displays one record for a certain month.

**********************************************
"Or, if you need all months, but want to group by month, you could do something like:

SELECT localdealer,year(dateoforder) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoforder),month(dateoforder)
ORDER BY year(dateoforder) desc, month(dateoforder) desc

Then, use the GROUP attribute on your CFOUTPUT on the month column -- you can then output a report for
each month per dealer."
**********************************************
0
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
LVL 1

Expert Comment

by:ndintenfass
ID: 6969946
It depends on how you want to display things.

Also, when using CFOUTPUT with the GROUP attribute you need to do a nested CFOUTPUT for the things you want output under each group.  It looks something like this:

<cfoutput group="month" query="yourQuery">
#month# #year#
<ul>
<cfoutput>
<li>#localdealer# - #SalesTotal#
</cfoutput>
</ul>
</cfoutput>

Is that what you want??



0
 

Author Comment

by:sagardeo
ID: 6971630
the code you just pasted give this as output:

Dealer Sales Total
4 2002
d005 $43.50
4 2002
d010 $99.00
4 2002
d014 $33.00
4 2002
d016 $132.00


this is what i want to get as output:

Dealer Sales Total
4 2002
d005 $43.50
d010 $99.00
d014 $33.00
d016 $132.00


and if there were multiple months, it should output like
this:

4 2002
d005 $43.50
d010 $99.00
d014 $33.00
d016 $132.00

5 2002
d005 $28.50
d010 $128.00
d014 $44.00
d016 $199.00

.
.
.
0
 
LVL 1

Accepted Solution

by:
ndintenfass earned 250 total points
ID: 6973583
I am confused then.  I built a little sample table that I think mimics your data.  My sample table looks like this:

DATEOFORDER FRN_ORDER_ID FRN_PRODUCT_ID ID LOCALDEALER PRICE QUANTITY
2002-01-01 00:00:00  3  101  1  d001  5.0000  2  
2002-01-05 00:00:00  4  102  2  d001  2.0000  1  
2001-04-01 00:00:00  5  103  3  d002  4.0000  3  
2002-03-01 00:00:00  6  104  4  d002  9.0000  1  
2002-04-15 00:00:00  7  105  5  d002  9.0000  1  
2002-04-01 00:00:00  8  106  6  d001  9.0000  4  


When I run the query:

SELECT localdealer,year(dateoforder) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoforder),month(dateoforder)
ORDER BY year(dateoforder) desc, month(dateoforder) desc


And then use this code:

<cfoutput group="month" query="getOrders">
#month# #year#
<ul>
<cfoutput>
<li>#localdealer# - #SalesTotal#
</cfoutput>
</ul>
</cfoutput>

I get this output:

4 2002
d001 - 36.0000
d002 - 9.0000
3 2002
d002 - 9.0000
1 2002
d001 - 12.0000
4 2001
d002 - 12.0000

Perhaps I need to see more of your code to know why we are getting different behaviors.


0
 

Author Comment

by:sagardeo
ID: 6977419
i made a syntax mistake. it works now. thanks.
0
 

Author Comment

by:sagardeo
ID: 6977883
ndintenfass, please see my new post with the same title. it's about the same question i asked but with a change.
thanks.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question