To use SUM( ) the column in question MUST be numeric type (int, decimal,
float etc).   Are you sure you are not trying to get a "count" rather than a
sum?   A sum totals all the columns together while a count (select
count(blah) as cBlah)  tells you the number of rows.

-Mark

-----Original Message-----
From: Andrew Golden [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 13, 2003 8:27 AM
To: CF-Talk
Subject: Re: Quick SQL Sum Question


At 03:27 PM 8/12/2003 -0500, you wrote:
>How can I easily nab the SUM of the inventory.service_shipping records
>returned in this query via SQL?   SUM blah AS cblah tosses an error, I
>suppose because just one part is aggregate?  Any quick ideas?

Have you tried SUM(blah) AS cblah? Sometimes odd little syntax errors have
driven me crazy for hours on end because they have worked differently
before...Just a thought. One other option(albeit not as efficient) is to
set a variable and loop through the query...I.E.

<cfquery name="get_productHOLDS" datasource="sddheinz">
SELECT
customer_orders_prod_shiphold.product_id,
customer_orders_prod_shiphold.qty,
customer_orders_prod_shiphold.line_total,
customer_orders_prod_shiphold.order_id,
inventory.service_name,
inventory.service_shipping,
inventory.service_desc
FROM customer_orders_prod_shiphold
LEFT OUTER JOIN inventory on
customer_orders_prod_shiphold.product_id = inventory.service_id
WHERE customer_orders_prod_shiphold.order_id =
<cfqueryparam cfsqltype="cf_sql_integer" value="#order_id#">
</cfquery>

<cfset sum = 0>
<cfloop query="get_productHOLDS">
         <cfset sum = sum + service_shipping>
</cfloop>


Good luck!

Andrew Golden



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. 
http://www.fusionauthority.com/ads.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to