Thanks to all who responded. Kevin and Bryan suggested using
sum(queryColumn) as xxx. However, I wanted to use this as an opportunity to
explore arrays, which I had not previously felt the need to use.

I found what I needed in ValueList and ListToArray. Three lines gives me
the desired results:

<cfset HoursArray = ListToArray(ValueList(getMainList.hours))>
<cfset TotalHours = ArraySum(HoursArray)>
<cfset Cost = TotalHours*65>

Regards,
--John




                                                                                       
             
                    Bryan Love                                                         
             
                    <BLove@xypoin        To:     CF-Talk <[EMAIL PROTECTED]>   
             
                    t.com>               cc:                                           
             
                                         Subject:     RE: Populate array with query    
             
                    03/01/2001                                                         
             
                    04:23 PM                                                           
             
                    Please                                                             
             
                    respond to                                                         
             
                    cf-talk                                                            
             
                                                                                       
             
                                                                                       
             




best to do math in the SQL of the query itself (if you are running a
query):

SELECT sum(hours) AS totalHours,
            sum(hours * 65) AS totalCost
FROM hoursTable
WHERE bla = bla

CF is extremely slow compared to enterprise level databases such as SQL
Server 7 and Oracle.  If you insist on using CF, however, do this:

<cfset totalHours = arraySum(getHours)>
<cfset cost = totalHours*65>
<CFOUTPUT>
    <P>The sum of the numbers is #totalHours# hours. At $65/hr,
this equals #dollarformat(cost)#
</CFOUTPUT>

Just leave the the ArraySum function out of the CFOUTPUT tags and you won't
get the YES output

Bryan Love ACP
[EMAIL PROTECTED]



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 01, 2001 1:58 PM
To: CF-Talk
Subject: Populate array with query


Hi,

Can someone suggest a better way to sum a numeric column in a query? The
solution is probably painfully simple, but I've been struggling for an hour
or two on it (only have online docs available).

<CFOUTPUT>#ArrayDeleteAt(GetHours,1)#</CFOUTPUT>
<CFLOOP query="getMainList">
   <CFOUTPUT>#ArrayAppend(GetHours, "#numberformat(hours)#")#</CFOUTPUT>
</CFLOOP>

Line 3 produces a string of "YES"s at the top of my output- one for every
record in the query.

The following gives me the result I need, but I can't get around the
display of the YES's that appears.

<cfset cost = ArraySum(GetHours)*65>
<CFOUTPUT>
    <P>The sum of the numbers is #ArraySum(GetHours)# hours. At $65/hr,
this equals #dollarformat(cost)#
</CFOUTPUT>

TIA,
--John
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to