No, but theoretically, if you know the char field has numbers in it (which
is I'm assuming why you asked the question), couldn't your first query do
this:
<cfquery name="q" datasource="myDSN">
Select sum(val(invoiceamount))
From invoices
</cfquery>
Not sure of which database you are using and what function it would be, but
the idea is that 'val()' will convert text to a number, if it's possible.
Another approach would be to do this:
<cfquery name="q" datasource="myDSN">
Select invoiceamount
From invoices
</cfquery>
<cfset iSumInvoices = arraySum(listToArray(valueList(q.invoiceamount)))>
Still, this begs the question, "why" would you want to put a number that you
want to sum in a char field in the first place, but I know that in some
circumstances, applications are the way they are because of bad design by a
previous developer and unfortunately, sometimes, they can't be changed when
you want to change them and you just "gotta make it work". :)
Dave
-----Original Message-----
From: Paul Kukiel [mailto:[email protected]]
Sent: Tuesday, February 24, 2009 12:25 PM
To: cf-newbie
Subject: RE: Sum
Rick,
I don't think it's possible to sum words and letters.
Paul.
-----Original Message-----
From: Rick Sanders [mailto:[email protected]]
Sent: Tuesday, February 24, 2009 1:08 PM
To: cf-newbie
Subject: RE: Sum
Thanks Paul,
Will it also work on char fields?
-----Original Message-----
From: Paul Kukiel [mailto:[email protected]]
Sent: February-24-09 2:00 PM
To: cf-newbie
Subject: RE: Sum
As a new query against the database:
<cfquery name="q" datasource="myDSN">
Select sum(invoiceamount)
From invoices
</cfquery>
Or
<cfquery name="q" dbtype="query">
Select sum(invoiceamount)
From 123
</cfquery>
Where 123 is the previous query.
Paul.
-----Original Message-----
From: Rick Sanders [mailto:[email protected]]
Sent: Tuesday, February 24, 2009 12:46 PM
To: cf-newbie
Subject: Sum
It's a newbie question so I'm posting it here.
I've looked through the documentation and can't find it. How do I sum a
column from a query?
Ex:
<cfoutput query=123>
#invoiceamount#
</cfoutput>
Is there a sum function like: #sum(invoiceamount)# or anything like that?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:4398
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15