Results 1 to 5 of 5
  1. #1
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83

    SQL syntax

    Instead of creating a query and running it against 2 tables I am attempting a subquery, however my experience is limited and below i am getting "Syntax error (missing operator) in join expression". The tbl "Area" has the primary key Facility




    Code:
    SELECT sum(Q.[SumOfTaxes]),[Area].[Facility], Sum([tbl1].[Payment]) AS [SumOfPayment]
    FROM
              (SELECT [tbl2].[Facility], Sum([tbl2].[Taxes]) AS [SumOfTaxes]
              FROM tbl2
              WHERE (((Month([Run Date]) & Year([Run Date]))=Month(Date()) & Year(Date())))
              GROUP BY [tbl2].[Facility]
              ) AS Q INNER JOIN [Area] ON [Q].[Facility] = [Area].[Facility] INNER JOIN [tbl1] ON [Area].[Facility] = [tbl1].[Facility]
    
    WHERE ((([tbl1].Time)="Month"))
    
    GROUP BY [Area].[Facility];

  2. #2
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    This line won't work: WHERE ((([tbl1].Time)="Month"))....what is the value of "Month" supposed to be (in your query "Month" = "Month")? What type of field is Time (date/time I would expect)? You need to compare like with like....so maybe month(tbl1.time) = month(date())?

  3. #3
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    Sorry I should have specified, that field has values "month", "year", "week" etc and I want the records with "month"

  4. #4
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    Did you figure it out yet? I would probably break it into pieces...bite-sized, of course...

  5. #5
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    I did, but I simplified my query a lot. I plan to expand on this through trial and error little by little. Part of my problem was not putting the proper field in the GROUP BY. Thanks.

    Code:
    SELECT Sum([tbl1].[Payment]) - Q.[SumCharge]) AS [Balance]
           
    FROM (SELECT Sum([Charge]) as SumCharge)AS Q, [tbl1]
    
    GROUP BY [Balance]

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

Similar Threads

  1. Help with syntax
    By GWB in forum Queries
    Replies: 4
    Last Post: 01-26-2011, 03:33 PM
  2. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  3. Please help SQL Syntax
    By jordanturner in forum Access
    Replies: 4
    Last Post: 09-02-2010, 08:05 AM
  4. Syntax error
    By smikkelsen in forum Access
    Replies: 6
    Last Post: 04-28-2010, 09:38 AM
  5. Syntax Contains Problem
    By pimlicosnail in forum Forms
    Replies: 9
    Last Post: 02-18-2010, 12:16 PM

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