Search code examples
sqlms-accessasp-classicweek-number

Simplest way to SELECT * FROM MyTable WHERE mydate is in specific week number?


Is there a simpel way to select and sum rows where the date is in a specific week number?

Something like this code?

mysum = RS.execute("Select Sum(mypoints) as sumpoints from MyTable WHERE 
  datepart(week, mydate) = '42'")("sumpoints")

Solution

  • Correct syntax for SQL statement and DatePart() function - uses default first day of week of Sunday:

    SELECT Sum(mypoints) AS sumpoints FROM MyTable WHERE DatePart("ww", mydate) = 42