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

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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

<cfif pcomor.recordcount lt nocomor>

should be

<cfif pcomor.recordcount lS nocomor>

<cfif pcomor.recordcount EQ nocomor>
RussoMAAuthor Commented:
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.

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

Then can you show some more code....

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RussoMAAuthor Commented:
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.
RussoMAAuthor Commented:
well there it is, it should be comorcount, not nocomor

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.