If I'm reading your question and code right, I believe you'll want to remove
query="getHighestDeptAverage"
from your second <cfoutput>.
You're not returning your query results here, but your have two results, therefore the second output.
Pergunta
I have this query (yes is long , working on making it better)
<cfquery datasource="Intranet" name="getHighestDeptAverage">
DECLARE @today DATETIME
SET @today = '2014-04-13'
;with CTE as(
Select d.csedept_name,d.csedept_id, Average = CASE WHEN d.csedept_question5 IS NULL
THEN (Select AVG(((cast(c.rating1 as Float)+ cast(c.rating2 as Float)+cast (c.rating3 as Float)+cast(c.rating4 as Float))/4))
From intranet.dbo.CSEReduxResponses c
Where c.employeedept = d.csedept_id
AND c.execoffice_status > 0
AND month(approveddate) = MONTH(@today))
ELSE (Select AVG(((cast(c.rating1 as Float)+ cast(c.rating2 as Float)+cast (c.rating3 as Float)+cast(c.rating4 as Float)+cast(c.rating5 as Float))/5))
From intranet.dbo.CSEReduxResponses c
Where c.employeedept = d.csedept_id
AND c.execoffice_status > 0
AND month(approveddate) = MONTH(@today))
END
from Intranet.dbo.CSEReduxDepts d
)
Select Top 2 Ranks = RANK() Over(Order By Average DESC),*
from CTE
</cfquery>
I want to output the top two ranks, This is what im doing:
<cfoutput query="getMaxstars">
<cfif rnk eq 1>
<cfset average_rating_max = total_stars>
<cfset average_rating_dept = first_name>
<cfset average_rating_dept_last_name = last_name>
</cfif>
<cfif rnk eq 2>
<cfset average_rating_max_runnerup = total_stars>
<cfset average_rating_dept_runnerup = first_name>
<cfset average_rating_dept_runnerup_last_name = last_name>
</cfif>
</cfoutput>
<cfoutput query="getHighestDeptAverage">
<h3>Winner: Department- #highest_dept_name_average#</h3>
<h3>Average: #hihest_dept_average# </h3>
<h4>Runner-up: Department- #highest_dept_name_runnerup# </h4>
<h4> Average: #highest_dept_name_average_runnerup# </h4>
</cfoutput>
Right now is outputing the result twice, and I only would like it to output once. I feel it should work since I do have another query that I do the same if and output so I not sure why is outputing twice?
Solução
If I'm reading your question and code right, I believe you'll want to remove
query="getHighestDeptAverage"
from your second <cfoutput>.
You're not returning your query results here, but your have two results, therefore the second output.