jeffmace
asked on
Help with SUM function
Please help me with this SUM function with a GROUP. I am trying to add the 'ArticleReviewCreditsClaim ed'. I have it displaying with the article name and its credit value, but I cannot get the credits to total. Please help.
<cfset TempIDs = 0>
<CFSET Total = 0>
<cfquery name="getEvals" datasource="#DataTables#">
Select * FROM ArticleEvalQueue
Where ArticleQueueStatus = 0
</cfquery>
<cfoutput query="getEvals">
<cfset TempIDs = listappend("#TempIDs#","#A rticleQueu eID#")>
</cfoutput>
<cfquery name="getProgram" datasource="#DataTables#">
SELECT ArticleEvalQueue.*, Articles.ArticleName, Articles.ArticleCMECredit, ArticleEvals.*, Articles.ArticleID,
SUM(ArticleEvaluations.Art icleReview CreditsCla imed) AS Total, Visitors.*
FROM ArticleEvalQueue INNER JOIN
ArticleEvals ON ArticleEvalQueue.ArticleQu eueID = ArticleEvals.ArticleQueueI D INNER JOIN
ArticleEvaluations ON ArticleEvals.ArticleEvalID = ArticleEvaluations.Article ReviewID INNER JOIN
Articles ON ArticleEvaluations.Article ID = Articles.ArticleID INNER JOIN
Visitors ON ArticleEvalQueue.ArticleQu eueVisitor ID = Visitors.VisitorID
WHERE ArticleEvals.ArticleQueueI D in(#TempIDs#)
Order by ArticleEvals.ArticleQueueI D ASC
</cfquery>
<table width="100%">
<cfoutput query="getProgram" group="ArticleQueueID">
<tr>
<td>
<STRONG>#VisitorFirstName# #VisitorLastName#</STRONG>
<cfoutput>
<li>#ArticleName# (#ArticleID# - #ArticleQueueID# - #ArticleReviewCreditsClaim ed#)</li>
</cfoutput>
</td>
</tr>
<tr><td>#total#</td></tr>
</cfoutput>
</table>
<cfset TempIDs = 0>
<CFSET Total = 0>
<cfquery name="getEvals" datasource="#DataTables#">
Select * FROM ArticleEvalQueue
Where ArticleQueueStatus = 0
</cfquery>
<cfoutput query="getEvals">
<cfset TempIDs = listappend("#TempIDs#","#A
</cfoutput>
<cfquery name="getProgram" datasource="#DataTables#">
SELECT ArticleEvalQueue.*, Articles.ArticleName, Articles.ArticleCMECredit,
SUM(ArticleEvaluations.Art
FROM ArticleEvalQueue INNER JOIN
ArticleEvals ON ArticleEvalQueue.ArticleQu
ArticleEvaluations ON ArticleEvals.ArticleEvalID
Articles ON ArticleEvaluations.Article
Visitors ON ArticleEvalQueue.ArticleQu
WHERE ArticleEvals.ArticleQueueI
Order by ArticleEvals.ArticleQueueI
</cfquery>
<table width="100%">
<cfoutput query="getProgram" group="ArticleQueueID">
<tr>
<td>
<STRONG>#VisitorFirstName#
<cfoutput>
<li>#ArticleName# (#ArticleID# - #ArticleQueueID# - #ArticleReviewCreditsClaim
</cfoutput>
</td>
</tr>
<tr><td>#total#</td></tr>
</cfoutput>
</table>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thnks for the points ;-)
I wonder what has * got to do with group attribute in CFQUERY ???
Jeffmace : if ur query was giving out the correct output - all u had to do was sum up the total inside the inner output tag !
I am assuming this based on the previous question - something like this MIGHT have worked for u
[keeping ur query as it is]
<TABLE WIDTH="100%">
<CFOUTPUT QUERY="getProgram" GROUP="ArticleQueueID">
<TR>
<TD><STRONG>#VisitorFirstN ame# #VisitorLastName#</STRONG>
<CFSET THISTOTAL = 0>
<CFOUTPUT>
<LI>#ArticleName# (#ArticleID# - #ArticleQueueID# - #ArticleReviewCreditsClaim ed#)</LI>
<CFSET THISTOTAL = (THISTOTAL + TOTAL)>
</CFOUTPUT>
</TD>
</TR>
<TR>
<TD>#ThisTotal#</TD>
</TR>
</CFOUTPUT>
</TABLE>
dont know if this is what u were looking for ... but thought wld give it a try !
K'Rgds
Anand
Jeffmace : if ur query was giving out the correct output - all u had to do was sum up the total inside the inner output tag !
I am assuming this based on the previous question - something like this MIGHT have worked for u
[keeping ur query as it is]
<TABLE WIDTH="100%">
<CFOUTPUT QUERY="getProgram" GROUP="ArticleQueueID">
<TR>
<TD><STRONG>#VisitorFirstN
<CFSET THISTOTAL = 0>
<CFOUTPUT>
<LI>#ArticleName# (#ArticleID# - #ArticleQueueID# - #ArticleReviewCreditsClaim
<CFSET THISTOTAL = (THISTOTAL + TOTAL)>
</CFOUTPUT>
</TD>
</TR>
<TR>
<TD>#ThisTotal#</TD>
</TR>
</CFOUTPUT>
</TABLE>
dont know if this is what u were looking for ... but thought wld give it a try !
K'Rgds
Anand
ASKER
Actually that is exactly what i wound up doing. At least i feel good about myself by figuring it out myself. :)
Then i wonder - why u accepted something - that was not a required answere for u .... weird :)
Cos someone looking at this thread tomorrow may be misguided to think - thats the real answere ... whereas infact it is not !
Cos someone looking at this thread tomorrow may be misguided to think - thats the real answere ... whereas infact it is not !
ASKER
Well I just took the correct answer as to say that I could not use the SUM function in this instance which made me look for another solution. So now if someone comes to this thread they will see that they can not use the SUM function here and then will see your answer as another method. So its actually helps in 2 different ways