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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculate a total for a column in a table

Status
Not open for further replies.

beckyh

Programmer
Apr 27, 2001
126
0
0
US
What would be the best way to achieve this? So far this is my code (but I am certainly not saying this is the best way to calculate a total); it is not calculating anything, just displaying a 0 (so it must be at least syntactically correct).

<cfset ChargeTot=0>
<cfif isdefined("NarAmt") or isdefined("ChargeAmt")>
<cfif GetPOonly.recordcount LT GetGLInfo.recordcount>
<cfloop query="GetGLInfo">
<cfset ChargeTot=ChargeTot+#NarAmt#+#ChargeAmt#>
</cfloop>
<cfelse>
<cfloop query="GetPOInfo">
<cfset ChargeTot=ChargeTot+#NarAmt#+#ChargeAmt#>
</cfloop>
</cfif>
</cfif>
 
my guess is <cfif isdefined("NarAmt") or isdefined("ChargeAmt")> never evaluates to true. if they are query values you need to use the full name. queryName.NarAmt and queryName.ChargeAmt

Technology is dominated by two types of people: those who understand what they do not manage, and those who manage what they do not understand. - Putt's Law
 
could we please see the GetPOonly and GetGLInfo queries?

i'm curious why you need the isDefined tests

also, i have a feeling you could get the answer easily with the ValueList function, or perhaps a query-of-queries, instead of the double CFLOOPs

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts May 8 2005)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top