为什么得到错误元素recordcount是未定义的?

时间:2014-12-02 22:06:51

标签: coldfusion

我有一个查询

SELECT csedept_name,submitterdept, COUNT(execoffice_status) as 'starsgiven'
FROM   Depts d 
       LEFT JOIN CSEReduxResponses c on d.csedept_id = c.submitterdept
                                    .......
                                    and YEAR ([approveddate]) =2014
                                    and month ([approveddate]) =12
                                    ....

当我在microsolf sql server studio上运行时,我得到了 20行返回,所有' submitterdept'空值。 但我一直收到这个错误:

Element RECORDCOUNT is undefined in GETBRANCHSTARS.

The error occurred in stars.cfm: line 498

496 : </cfif>
497 : <cfset totalbranch =0 >
498 : <cfif getbranchstars.recordcount gt 0>
499 : 
500 :   <h1> Counts </h1

由于某种原因无法识别记录计数。

我做错了什么?

<cfset totalbranch =0 >

<cfif getbranchstars.recordcount gt 0>  
    <table >
        <thead><tr><th>Branch</th><th>Stars Given</th></tr></thead>
        <tbody>
        <cfoutput query="getbranchstars" >
        <tr>
        <td>#CSEDEPT_NAME#</td>
        <td>#BRANCHTOTALSTARSGIVEN#</td>
        </tr>
        <cfset totalbranch += BRANCHTOTALSTARSGIVEN>
        </cfoutput>
        </tbody>

     <tfoot>
        <cfoutput>
        <tr>
        <th>&nbsp;</th>
        <th><div align="left">#totalbranch#</div></th>
        </tr>
        </cfoutput>
    </tfoot>

    </table>

<cfelse>
<p>No Branch Department Counts</p>
</cfif>

2 个答案:

答案 0 :(得分:0)

运行在应用程序onRequest上切换会话范围设置的例程时出现此错误,这会影响条件逻辑是否运行查询。当会话范围设置设置为执行查询时,后续代码将根据该会话范围设置运行,以便在RECORDCOUNT时输出数据。在没有切换的情况下随后调用同一页面时,页面运行正常。因此,显然CF在某种程度上正在及时运行新的会话设置以运行查询但是没有及时运行所有内务处理以将recordCount附加到查询对象。我取出了会话范围的条件是否运行查询,我不再收到丢失的RECORDCOUNT错误。

答案 1 :(得分:-1)

我也遇到了这个错误。在我的例子中,我通过将结果参数添加到cfquery,result="result_name"来解决了这个问题。然后将query_name.recordcount更改为result_name.recordcount