ERROR:"Complex object types cannot be converted to simple values." (in a cfloop statement)

Posted on 2006-03-20
Last Modified: 2013-12-24

Error Occurred While Processing Request  
Complex object types cannot be converted to simple values.  
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a <CFIF> tag. This was possible in ColdFusion 2.0 but creates an error in later versions.
The error occurred in C:\Inetpub\wwwroot\reporting4.cfm: line 172
Called from C:\Inetpub\wwwroot\reporting4.cfm: line 171
Called from C:\Inetpub\wwwroot\reporting4.cfm: line 156
Called from C:\Inetpub\wwwroot\reporting4.cfm: line 1
170 : #Comor#,
171 : </cfoutput><cfoutput>
172 : <cfif pcomor.recordcount lt nocomor><cfset commacount = pcomor.recordcount - nocomor><cfloop index="x" from="1" to="#commacount#">,</cfloop></cfif>
173 : #dateformat(LastFUDate,'mm/dd/yyyy')#,#LosttoFU#,#Location#,
174 : <cfquery datasource="prostate" name="pdiagstag">

 ____<end of error>____
here's the background

pcomor = query
nocomor = number set earlier by a query

the line that is being referred to with the error:
<cfif pcomor.recordcount lt nocomor><cfset commacount = pcomor.recordcount - nocomor><cfloop index="x" from="1" to="#commacount#">,</cfloop></cfif>

what I am doing is earlier i have a query set up that tells the max count of records that could possibly be spanned across the CSV output i am creating.  (this is nocomor variable)
when i loop through some of the inner queries in my dataset, they may not have as many elements of data, so i am trying to add a , (comma) after those for each missing element
(this is the [pcomor.recordcount - nocomor] expression which i want to use for my loop variable to tell the loop how many extra comma's are needed to express the elements)

any alternate way to do this, or finding what i need to do in my code will be acknowledged as correct.
Question by:RussoMA
    LVL 35

    Expert Comment

    <cfif pcomor.recordcount lt nocomor>

    should be

    <cfif pcomor.recordcount lS nocomor>

    <cfif pcomor.recordcount EQ nocomor>

    Author Comment

    no, i am pretty sure i want it to only do that if the recordcount is less than the max possible number of rows

    data i want to look like this:

    data1,data2,data3  (where it doesnt call the loop)
    data1,data2,,         (where it calls the loop and adds 1 comma [pcomor.recordcount is 2, nocomor is 3])
    data1,,,                 (add 2 commas, [pcomor.recordcount is 1, nocomor 3])

    (i think i just answered my own question there, let me test)  nope, still same problem

    but now my expression is <cfset commacount = nocomor - pcomor.recordcount>

    because that pcomor query runs within a loop for each row of data.  it is just a small subsection of the rest of the data that is on the same row.

    LVL 35

    Accepted Solution

    Oh is that a LT - it looked like an IT as in a typo.

    Then can you show some more code....

    Author Comment

    here's the code for the count variable:

    <cfquery datasource="mydata1" name="nocomor">
    SELECT PatientCoMor.PatientSer, Count(PatientCoMor.PatientSer) AS CountOfPatientSer
    FROM PatientCoMor INNER JOIN CoMor ON PatientCoMor.CoMorSer = CoMor.CoMorSer
    GROUP BY PatientCoMor.PatientSer
    <cfset comorcount = 0>
    <cfoutput query="nocomor">
    <cfif countofpatientser gt comorcount><cfset comorcount = countofpatientser></cfif>

    here's the area around the error:

    <cfquery datasource="mydata1" name="pcomor">
    SELECT CoMor.CoMor, PatientCoMor.PatientSer
    FROM PatientCoMorINNER JOIN CoMorb ON PatientCoMor.CoMorSer = CoMorb.CoMorSer
    WHERE PatientComor.PatientSer like '#PatientSer#'
    <cfoutput query="pcomor">
    <cfif pcomor.recordcount lt nocomor><cfset commacount = nocomor - pcomor.recordcount><cfloop index="x" from="1" to="#commacount#">,</cfloop></cfif>

    that code is encapsulated within a cfloop that holds the variable PatientSer as the active record and it is a cfloop query loop, just to rule out duplication of the index variable.

    Author Comment

    well there it is, it should be comorcount, not nocomor


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
    Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now