GROUP BY WEEK

  • is it possible in a sql 2000 database

    select query to group a time_date field

    weekly or monthly

    it is stored in the database by day ?

    cheers

  • by using Datename() function u can group

    in weekly or monthly

  • 
    
    SELECT MONTH(DateField) , YEAR(DateField), COUNT(*)
    FROM MyTable
    GROUP BY MONTH(DateField) , YEAR(DateField)
    HAVING COUNT(*) > 0
  • Hi Jay,

    Just being picky but why do have 'HAVING COUNT(*) > 0' in the query? Is it not superfluous as the query cannot return month/year with a count of 0?

    Edited by - davidburrows on 07/22/2003 06:31:49 AM

    Far away is close at hand in the images of elsewhere.
    Anon.

  • quote:


    Hi Jay,

    Just being picky but why do have 'HAVING COUNT(*) > 0' in the query? Is it not superfluous as the query cannot return month/year with a count of 0?

    Edited by - davidburrows on 07/22/2003 06:31:49 AM


    You're right David. An unfortunate COPY and PASTE error (I was copying a similar solution using a detail table and didn't remove the HAVING clause. Good spot!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply