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

quarterly-total

Status
Not open for further replies.

gatetec

MIS
Mar 22, 2007
420
US
I have a working version of cfquery below.
It gives monthly sub-total and grand-total.

Is there a way to put quarterly-total so that it can give like this:

Jan Feb Mar 1st Qtr Apr May June 2nd Qtr July Aug Sept 3rd Qtr Oct Nov Dec 4th Qtr Annual

I need quarterly sum for horizontal and vertical.

<cfquery name="qGetMonth" datasource="mydb">
select distinct datepart (mm, VisitDate) as TheMonth
from DailyLog
where datepart (mm, VisitDate) !=''
order by datepart (mm, VisitDate)
</cfquery>

<cfquery name="qGetVisitReason" datasource="mydb">
SELECT DISTINCT VisitReason
FROM DailyLog
where VisitReason != '' and ....
ORDER BY VisitReason
</cfquery>



<table border="1" cellpadding="3" cellspacing="1" align="center">
<tr align="center">
<td>Visit Count/Month for <cfoutput>#form.YearSelection#</cfoutput></td>
<cfoutput query="qGetMonth">
<td>#TheMonth#</td>
</cfoutput>
<td>Subtotal</td>
</tr>

<cfset OverallVisitReasonTotal = 0>

<cfoutput query="qGetVisitReason">
<tr>
<cfset MainVisitReason = VisitReason>
<td>#MainVisitReason#</td>
<cfset VisitReasonTotal = 0>

<cfloop query="qGetMonth">
<cfset MainMonth = TheMonth>
<cfquery name="qGetRecord" datasource="mydb">
SELECT count(VisitReason) as TotalCount
FROM DailyLog
WHERE VisitReason = <cfqueryparam cfsqltype="cf_sql_varchar" value="#MainVisitReason#">
AND datepart (mm, VisitDate) = <cfqueryparam cfsqltype="cf_sql_varchar" value="#MainMonth#">
<cfif form.YearSelection neq "select">
AND datepart(yy, VisitDate) = #form.YearSelection#
</cfif>
AND VisitReason !='' ....
</cfquery>

<cfif qGetRecord.recordcount>
<cfset Count = qGetRecord.TotalCount>
<cfelse>
<cfset Count = 0>
</cfif>
<cfif VisitReasonTotal eq "">
<cfset VisitReasonTotal =0>
</cfif>
<cfif Count eq "">
<cfset Count =0>
</cfif>
<cfset VisitReasonTotal = VisitReasonTotal + Count>
<td><div align="right">#Count#</div></td>
</cfloop>

<cfset OverallVisitReasonTotal = OverallVisitReasonTotal + VisitReasonTotal>
<td><div align="right">#VisitReasonTotal#</div></td>
</tr>
</cfoutput>
<tr align="right">
<td align="left">SubTotal</td>
<cfoutput>
<cfloop query="qGetMonth">
<cfset MonthTotal = 0>
<cfset MainMonth = TheMonth>
<cfquery name="qGetMonthTotal" datasource="mydb">
SELECT count(VisitReason) as SubTotal
FROM DailyLog
WHERE datepart (mm, VisitDate) = <cfqueryparam cfsqltype="cf_sql_varchar" value="#MainMonth#">
AND VisitReason !='' ...
<cfif form.YearSelection eq "select">
<cfelse>
and datepart(yy, VisitDate) = #form.YearSelection#
</cfif>
</cfquery>

<cfif qGetMonthTotal.recordcount eq "" or MonthTotal eq "">
<cfset MonthTotal = 0>
<cfelse>
<cfset MonthTotal = MonthTotal + qGetMonthTotal.SubTotal>
</cfif>

<td><div align="right">#MonthTotal#</div></td>
</cfloop>
<td><div align="right">#OverallVisitReasonTotal#</div></td>
</cfoutput>
</tr>
</table>

thx much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top