Need help with Access SQL Query (Dates)

Results 1 to 2 of 2

Thread: Need help with Access SQL Query (Dates)

  1. #1
    Spikeh Guest

    Default Need help with Access SQL Query (Dates)

    Ok, heres the thing, it&#039;s probably quite trivial but it&#039;s been annoying me for days now :/<BR><BR>I need a SQL SELECT query that does the following:<BR><BR>Selects the present month and it&#039;s corresponding year from a date field in a table, and ALSO the previous 2 months (Just the month numbers, so for example, if it was January, 2001 I&#039;d want the Recordset to return:<BR>Record 1: ExprMonth=1 , ExprYear=2001<BR>Record 2: ExprMonth=12 , ExprYear=2000<BR>Record 3: ExprMonth=11 , ExprYear=2000<BR><BR>The date filed is in the following format (Not that it matters too much): e.g. "27/03/2001 2:00:00 PM" and every date is different (At the moment there are about 30 entries, all test data, but as you can imagine the DB will grow substantialy due to it being a news script.)<BR><BR>I&#039;m using Access, ODBC through ASP so I just need a SQL statement that will work with Access drivers.<BR><BR>Anything will help as I&#039;ve been tearing my hair out for 2 days trying to get this to work :/ Thanks guys/gals

  2. #2
    Join Date
    Dec 1969

    Default Suggesting a Database re-work

    I suggest splitting the date field into two fiels, one for date and one for time...<BR><BR>That will allow your SQL queries to be less-complicated...<BR><BR>As far as your SQL query, I don&#039;t understand what you are getting from where....<BR><BR>You don&#039;t need a special query to pull just the month, you pull the data in the database, and use ASP functions to pull the month...<BR>eg:<BR>dat = "10-5-01"<BR>response.write(month(dat) & " Year: " & year(Dat))<BR><BR>"10 Year: 2001" will be printed.<BR><BR>-- Whol

Posting Permissions

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