Skip to main content
Inspiring
August 2, 2006
Answered

help with error message please

  • August 2, 2006
  • 1 reply
  • 718 views
GOAL:
I want to be able to add values together from the database that match the current week number

SETUP:
Database field walkDate is a date field
variable curWeek finds the current week number

ERROR:
Error Executing Database Query.

Query Of Queries runtime error.
Column "fullQuery.walkDate" is invalid in the "SELECT list" clause because it is not contained in an aggregate function, and there is no GROUP BY clause

The error occurred in \\NAWINFS02\home\users\web\b947\rh.2onboard\walks.cfm: line 40

38 : sum(fullQuery.distance) AS curWeekDistance
39 : FROM fullQuery
40 : WHERE #week(fullQuery.walkDate)# = #curWeek#
41 : </cfquery>
42 :

--------------------------------------------------------------------------------

SQL SELECT fullQuery.walkDate, sum(fullQuery.distance) AS curWeekDistance FROM fullQuery WHERE 31 = 31

CODE:
<!--- MAIN QUERY --->
<cfset curWeek = #week(NOW())#>
<cfset curMonth = #month(NOW())#>
<cfset curYear = #year(NOW())#>

<cfquery name="fullQuery" datasource="2onboard">
SELECT *
FROM bockWalk
ORDER BY walkDate
</cfquery>
<cfoutput query="fullQuery"><cfset lastID=#fullQuery.recordCount#></cfoutput>

<cfquery name="lastEntry" dbtype="query">
SELECT *
FROM fullQuery
WHERE ID=#lastID#
</cfquery>

<cfquery name="nowWeek" dbtype="query">
SELECT fullQuery.walkDate,
sum(fullQuery.distance) AS curWeekDistance
FROM fullQuery
WHERE #week(fullQuery.walkDate)# = #curWeek# <!--- Need to add current year to this --->
<!--- Need to calculate time also --->
</cfquery>
    This topic has been closed for replies.
    Correct answer jkgiven
    I played with this a bit. I suspect the problem is that QoQ does not
    support any date functions. Can you modify the SQL that generates the
    fullQuery recordset to create columns for month and year using your DBMS
    syntax to parse dates that you can then filter on in the QoQ sql.

    For example in pseudoCode.

    <cfquery name="fullQuery" dataSource="aDSN"..>
    SELECT
    month(dateField) AS MonthField,
    year(dateField) AS YearField,
    ....
    </cfquery>

    jkgiven wrote:
    > If I remove the pound signs to the left of the "=" in the WHER clause, then I
    > get error:
    > Error Executing Database Query.
    >
    > Query Of Queries syntax error.
    > Encountered "Month. Incorrect conditional expression, Expected one of
    > [like|null|between|in|comparison] condition,
    >
    > The error occurred in \\NAWINFS02\home\users\web\b947\rh.2onboard\walks.cfm:
    > line 39
    >
    > 37 : FROM fullQuery
    > 38 : WHERE Month(fullQuery.walkDate) = #curMonth# AND
    > 39 : Year(fullQuery.walkDate) = #curYear#
    > 40 : </cfquery>
    > 41 :
    >
    >
    > --------------------------------------------------------------------------------
    >
    > SQL SELECT sum(fullQuery.distance) AS curMonthDistance FROM fullQuery WHERE
    > Month(fullQuery.walkDate) = 8 AND Year(fullQuery.walkDate) = 2006
    >

    I made it into its' own query and it worked fine
    Thank You for you help and time

    1 reply

    Inspiring
    August 2, 2006
    The error is a straight forward SQL error. When you use an aggregate
    function, eg (sum) in a select statement, all fields in the select
    statement must use an aggregate function or be part of the order by cluase.

    SELECT fullQuery.walkDate, sum(fullQuery.distance) AS curWeekDistance
    FROM fullQuery
    WHERE #week(fullQuery.walkDate)# = #curWeek#
    ORDER BY fullQuery.walkDate

    This is not going to solve all your problems. You are using a CF
    function on th left side of the WHERE cluase. If you look at the
    resulting SQL you are getting WHERE 31 = 31. This will always be true
    so that you will get all the records. You need to be using the SQL
    equivalent to the CF week() function. What that is will depend on which
    DBMS you are using, but they all have something. You will also want to
    use this function in the order by clause otherwise you will not be
    getting the sums you are expecting.


    jkgiven wrote:
    > GOAL:
    > I want to be able to add values together from the database that match the
    > current week number
    >
    > SETUP:
    > Database field walkDate is a date field
    > variable curWeek finds the current week number
    >
    > ERROR:
    > Error Executing Database Query.
    >
    > Query Of Queries runtime error.
    > Column "fullQuery.walkDate" is invalid in the "SELECT list" clause because it
    > is not contained in an aggregate function, and there is no GROUP BY clause
    >
    > The error occurred in \\NAWINFS02\home\users\web\b947\rh.2onboard\walks.cfm:
    > line 40
    >
    > 38 : sum(fullQuery.distance) AS curWeekDistance
    > 39 : FROM fullQuery
    > 40 : WHERE #week(fullQuery.walkDate)# = #curWeek#
    > 41 : </cfquery>
    > 42 :
    >
    >
    > --------------------------------------------------------------------------------
    >
    > SQL SELECT fullQuery.walkDate, sum(fullQuery.distance) AS curWeekDistance
    > FROM fullQuery WHERE 31 = 31
    >
    > CODE:
    > <!--- MAIN QUERY --->
    > <cfset curWeek = #week(NOW())#>
    > <cfset curMonth = #month(NOW())#>
    > <cfset curYear = #year(NOW())#>
    >
    > <cfquery name="fullQuery" datasource="2onboard">
    > SELECT *
    > FROM bockWalk
    > ORDER BY walkDate
    > </cfquery>
    > <cfoutput query="fullQuery"><cfset lastID=#fullQuery.recordCount#></cfoutput>
    >
    > <cfquery name="lastEntry" dbtype="query">
    > SELECT *
    > FROM fullQuery
    > WHERE ID=#lastID#
    > </cfquery>
    >
    > <cfquery name="nowWeek" dbtype="query">
    > SELECT fullQuery.walkDate,
    > sum(fullQuery.distance) AS curWeekDistance
    > FROM fullQuery
    > WHERE #week(fullQuery.walkDate)# = #curWeek# <!--- Need to add current year to
    > this --->
    > <!--- Need to calculate time also --->
    > </cfquery>
    >
    > <!--- MAIN QUERY --->
    > <cfset curWeek = #week(NOW())#>
    > <cfset curMonth = #month(NOW())#>
    > <cfset curYear = #year(NOW())#>
    >
    > <cfquery name="fullQuery" datasource="2onboard">
    > SELECT *
    > FROM bockWalk
    > ORDER BY walkDate
    > </cfquery>
    > <cfoutput query="fullQuery"><cfset lastID=#fullQuery.recordCount#></cfoutput>
    >
    > <cfquery name="lastEntry" dbtype="query">
    > SELECT *
    > FROM fullQuery
    > WHERE ID=#lastID#
    > </cfquery>
    >
    > <cfquery name="nowWeek" dbtype="query">
    > SELECT fullQuery.walkDate,
    > sum(fullQuery.distance) AS curWeekDistance
    > FROM fullQuery
    > WHERE #week(fullQuery.walkDate)# = #curWeek# <!--- Need to add current year to
    > this --->
    > <!--- Need to calculate time also --->
    > </cfquery>
    >
    >
    > #nowWeek.curWeekDistance#
    >
    jkgivenAuthor
    Inspiring
    August 2, 2006
    Ian - thanks for your time

    not really sure what I have to do now, but I'll take what you have written and try to rethink my approach - I'm using an Access DB so maybe I can start in its' query tool to get help in my rewrite.