I am having trouble with looping over a query in order to get totals for events in different categories and also per month. The first CFLOOP Query works for the year, but the next one which is the problem is not working, How can I get each category total to output per month, I am not getting the results.
I would really appreciate any suggestions to get this to work.
Thanks,
olmos
<cfoutput>
<CFQUERY NAME="categories" DATASOURCE="#PrimaryDataSource#" >
SELECT eventcategory_id
FROM eventcategory
</cfquery>
<CFQUERY NAME="events" DATASOURCE="#PrimaryDataSource#" >
SELECT distinct to_char(e.notification_date, 'MON-YY') month_year , c.eventcategory_id, c.event_id
FROM computer c, event e
Where c.event_id = e.event_id
AND e.notification_date BETWEEN '#fiscal_year_start#' AND '#fiscal_year_end#'
ORDER BY month_year
</cfquery>
***This is ok I do get the totals for each category for the year***
<cfloop query = "categories">
<CFQUERY NAME="get_event_by_cat" DATASOURCE="#PrimaryDataSource#" >
SELECT count(c.event_id) "total"
FROM computer c, event e
Where c.event_id = e.event_id
AND e.notification_date BETWEEN '#fiscal_year_start#' AND '#fiscal_year_end#'
AND c.eventcategory_id = '#eventcategory_id#'
</cfquery>
<cfset event_id = ''>
<cfloop query="get_event_by_cat">
<cfset event_id = ListAppend(event_id, total)>
<tr>
<td> #total#</td>
</tr>
</cfloop>
</cfloop>
</cfoutput>
*** Here is the problem , I am not getting the totals for each month,
and it is not looping through each category, What am I doing wrong ?,
How can I get each category total to output per month, I just get DEC-01
***
<cfoutput>
<cfloop query = "events">
<CFQUERY NAME="get_event_by_month" DATASOURCE="#PrimaryDataSource#" >
SELECT count(to_char(e.notification_date, 'MON-YY')) as "totalmonth"
FROM computer c, event e
Where c.event_id en (#event_list#)
AND c.event_id = e.event_id
AND c.eventcategory_id = '#eventcategory_id#'
AND e.notification_date = to_date('#events.month_year#', 'MON-YY')
</cfquery>
<cfset month = ''>
<cfloop query="get_event_by_month">
<cfset month = ListAppend(month, totalmonth)>
<tr>
<td>total for #events.month_year# #totalmonth#</td>
</tr>
<tr><td></td></tr>
</cfloop>
</cfloop>
</cfoutput>
I would really appreciate any suggestions to get this to work.
Thanks,
olmos
<cfoutput>
<CFQUERY NAME="categories" DATASOURCE="#PrimaryDataSource#" >
SELECT eventcategory_id
FROM eventcategory
</cfquery>
<CFQUERY NAME="events" DATASOURCE="#PrimaryDataSource#" >
SELECT distinct to_char(e.notification_date, 'MON-YY') month_year , c.eventcategory_id, c.event_id
FROM computer c, event e
Where c.event_id = e.event_id
AND e.notification_date BETWEEN '#fiscal_year_start#' AND '#fiscal_year_end#'
ORDER BY month_year
</cfquery>
***This is ok I do get the totals for each category for the year***
<cfloop query = "categories">
<CFQUERY NAME="get_event_by_cat" DATASOURCE="#PrimaryDataSource#" >
SELECT count(c.event_id) "total"
FROM computer c, event e
Where c.event_id = e.event_id
AND e.notification_date BETWEEN '#fiscal_year_start#' AND '#fiscal_year_end#'
AND c.eventcategory_id = '#eventcategory_id#'
</cfquery>
<cfset event_id = ''>
<cfloop query="get_event_by_cat">
<cfset event_id = ListAppend(event_id, total)>
<tr>
<td> #total#</td>
</tr>
</cfloop>
</cfloop>
</cfoutput>
*** Here is the problem , I am not getting the totals for each month,
and it is not looping through each category, What am I doing wrong ?,
How can I get each category total to output per month, I just get DEC-01
***
<cfoutput>
<cfloop query = "events">
<CFQUERY NAME="get_event_by_month" DATASOURCE="#PrimaryDataSource#" >
SELECT count(to_char(e.notification_date, 'MON-YY')) as "totalmonth"
FROM computer c, event e
Where c.event_id en (#event_list#)
AND c.event_id = e.event_id
AND c.eventcategory_id = '#eventcategory_id#'
AND e.notification_date = to_date('#events.month_year#', 'MON-YY')
</cfquery>
<cfset month = ''>
<cfloop query="get_event_by_month">
<cfset month = ListAppend(month, totalmonth)>
<tr>
<td>total for #events.month_year# #totalmonth#</td>
</tr>
<tr><td></td></tr>
</cfloop>
</cfloop>
</cfoutput>