Results 1 to 3 of 3

Thread: Writing SQL [RESOLVED]

Hybrid View

  1. #1
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Writing SQL

    I wouldn't use month as a field name since it's also the name of a function in VB.
    Anyway, instead of your WHERE clause, try a GROUP BY month.
    Tengo mas preguntas que contestas

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Writing SQL

    To expand on salvelinus's post...

    You want the montha nd a (sum) total of spend, yet in your Sql you only bring back one sum field and filter on a where.
    Tru this works, but you'd need sub queries for each month.

    As salvelinus posted, use a group by.

    Code:
    SELECT 
       [table1].[month]
       ,Sum(spent) AS Total
    FROM 
       table1
    GROUP BY
       [table1].[month]
    When you use group by you must list all fields that are not aggregate functions (sum, max, min etc).

    Try the above then mess around with the sql, see what happens.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width