Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access queries and/or CF arith. expressions

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm still relatively new to coding CF, but here's what I'm trying to do - I'm trying to code one of my templates so that it retrieves a column of numbers from a database table, sum them all dynamically, have the same happen to another column, then have one of those sums divided by the other, also in real time dynamically. Any suggestions on how I would build a query like this in MS Access, or just by coding it with CF? Thanks.
 
Try this (there is probably a more effiect way to do this using SQL, but I am not as confident with SQL statements, and did not have time to do a test, sorry):

<cfquery name=&quot;theQuery&quot; DATASOURCE=&quot;#ODBC_DATASOURCE#&quot;>
Select column1, column2
FROM Database
Where this = that
</cfquery>

<cfset var1=0>
<cfset var2=0>
<cfoutput query=&quot;theQuery&quot;>
<cfset var1 = var1 + column1>
<cfset var2 = var2 + column2>
</cfoutput>

<cfset theAnswer = var1/var2>

Hope this helps. There is a sum function for sql, which I think would be more efficient though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top