Skip to main content
Inspiring
February 21, 2008
Answered

Query Of Queries syntax error.

  • February 21, 2008
  • 1 reply
  • 4269 views
Hi all,

I have the following query:

<cfquery name="agent" datasource="datasourcename">
SELECT * FROM quotes where status = 'Pending'
<cfif isDefined("form.agent")>
AND agent = '#FORM.agent#'
</cfif>
</cfquery>

Then, I have the following query of that query

<cfquery name="totalvalue" dbtype="query">
SELECT SUM(value) as total FROM agent
</cfquery>

however I get the following error:

Query Of Queries syntax error.
Encountered "SUM ( value. Incorrect Select List,

on line 20 which is:

<cfquery name="totalvalue" dbtype="query">

now i'm sure this is identical to what ive used before but getting the error. the totals query works fine when querying the database direct, only got this error when I changed it to query the master query.

i appreciate any help in advance, as no matter how much i stare at it I can't see whats wrong!
    This topic has been closed for replies.
    Correct answer paross1
    I believe that value is a reserved word that is probably causing your current error. I would rename this column, or alias it in your original query. Also, I would add WHERE value IS NOT NULL to your Q-of-Q to cover your NULLs.

    Phil

    1 reply

    Participating Frequently
    February 21, 2008
    Can value be null? Is value numeric?

    Phil
    Inspiring
    February 21, 2008
    Thanks for the reply.

    At the moment, its set as INTEGER and YES it can be Null.

    Do I need to make it notNull?
    paross1Correct answer
    Participating Frequently
    February 21, 2008
    I believe that value is a reserved word that is probably causing your current error. I would rename this column, or alias it in your original query. Also, I would add WHERE value IS NOT NULL to your Q-of-Q to cover your NULLs.

    Phil