Solved

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

Posted on 2002-04-24
8
160 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
  • 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
 
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
Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

 

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

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion update database with CFLOOP 5 60
Forbidden errors 5 123
question about access to website 2 68
Why is my Splunk Web URL not working? 2 51
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now