Results 1 to 5 of 5
  1. #1
    GWB is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2011
    Posts
    5

    Help with syntax

    Hello - my question is why does this query run fine:



    Code:
    SELECT sum(AvgOfCurrentSteamFlow)
    FROM [SELECT dbo_Boiler_Steam_Production.ReadingDate AS Expr1, Hour([ReadingTime]) AS Expr3, Avg(dbo_Boiler_Steam_Production.CurrentSteamFlow) AS AvgOfCurrentSteamFlow 
    FROM dbo_Boiler_Steam_Production
    GROUP BY dbo_Boiler_Steam_Production.ReadingDate, Hour([ReadingTime])
    HAVING (((Year([ReadingDate]))=[Select Year]))]. AS [%$##@_Alias];
    But this gives me a bracketing error:



    Code:
     
    SELECT sum(AvgOfCurrentSteamFlow)
    FROM [SELECT dbo_PWL_Boiler_Steam_Production.ReadingDate AS Expr1, Hour([ReadingTime]) AS Expr3, Avg(dbo_PWL_Boiler_Steam_Production.CurrentSteamFlow) AS AvgOfCurrentSteamFlow 
    FROM dbo_PWL_Boiler_Steam_Production
    GROUP BY dbo_PWL_Boiler_Steam_Production.ReadingDate, Hour([ReadingTime])
    HAVING (((Year([ReadingDate]))=[Select Year]))]. AS [%$##@_Alias];
    Thanks for any help!

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Actually, I couldn't get either one to execute.

    I found that there as a dot (.) that shouldn't be there and the alias should be on the FROM clause in the subquery, not on the HAVING clause of the main query.


    Here is the first query:

    Code:
    SELECT Sum(AvgOfCurrentSteamFlow) AS Expr2
    FROM (SELECT ReadingDate AS Expr1, Hour([ReadingTime]) AS Expr3, Avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow 
    FROM dbo_Boiler_Steam_Production AS [%$##@_Alias] 
    GROUP BY ReadingDate, Hour([ReadingTime]))
    WHERE (((Year([ReadingDate]))=[Select Year]));
    Here is the second query:

    Code:
    SELECT Sum(AvgOfCurrentSteamFlow) AS Expr2
    FROM (SELECT ReadingDate AS Expr1, Hour([ReadingTime]) AS Expr3, Avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow 
    FROM dbo_PWL_Boiler_Steam_Production AS [%$##@_Alias] 
    GROUP BY ReadingDate, Hour([ReadingTime]))
    WHERE (((Year([ReadingDate]))=[Select Year]));

  3. #3
    GWB is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2011
    Posts
    5
    Thanks for that reply. I did try it and what happened is the query asked me to input a ReadingDate.... my original query just asks for a year. What I'm trying to do is get the total of all the averages. Strangely enough I did get it to work with this:

    Code:
    SELECT sum(AvgOfCurrentSteamFlow)
    FROM [SELECT dbo_PWL_Boiler_Steam_Production.ReadingDate AS Expr1, Hour([ReadingTime]) AS Expr3, Avg(dbo_PWL_Boiler_Steam_Production.CurrentSteamFlow) AS AvgOfCurrentSteamFlow   
     FROM dbo_PWL_Boiler_Steam_Production
     GROUP BY dbo_PWL_Boiler_Steam_Production.ReadingDate, Hour([ReadingTime])
     HAVING (((Year([ReadingDate]))=[Select Year]))]. AS [%$##@_Alias];
    I dont understand why but noticed that the code is shifted around by access and then works.

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Access changes "()" around a subquery to "[]." quietly, then tell you there is syntax error.

  5. #5
    GWB is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2011
    Posts
    5
    Quote Originally Posted by weekend00 View Post
    Access changes "()" around a subquery to "[]." quietly, then tell you there is syntax error.
    Thanks for that -I thought I was going mad!
    I'm going to start a new thread with a query built from scratch

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  2. Please help SQL Syntax
    By jordanturner in forum Access
    Replies: 4
    Last Post: 09-02-2010, 08:05 AM
  3. dlookup() syntax
    By markjkubicki in forum Programming
    Replies: 4
    Last Post: 08-24-2010, 12:31 PM
  4. Syntax error
    By smikkelsen in forum Access
    Replies: 6
    Last Post: 04-28-2010, 09:38 AM
  5. Looping syntax
    By fadiaccess in forum Access
    Replies: 1
    Last Post: 10-23-2009, 02:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums