Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

SQL Query Beetween <Month> AND <Month>?

If I need to retrieve all records from OCT 2007 to NOV 2007 (inclusive of FEB) how should I build the query?

I tried this but it only returns me records from October.

SELECT *

FROM SNTPEN

WHERE (HB_DATE BETWEEN 'OCT 2007' AND 'NOV 2007')

Update:

It is true then when I changed NOV to DEC the results will return what I want but the thing is client will input the period through a webpage.

Something like from OCT 2007 to NOV 2007 and they expect to get all data from OCT to NOV.

I know I can always create a function to increment the month but just would like to know whether is it possible to do on the SQL end.

Update 2:

There are only Month and Year, the client does not want Date to be included because it is a bi-weekly & monthly report.

5 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    i will definitely return only records from "oct 1 2007"

    to "nov 1 2007"... ^^

    im in mssql and i can't see why ur expecting records from

    Feb...

    in tsql, if you omit the month, it will default to "january",

    if day is omitted, it will default to "1",

    and if time is omitted, will default to "12:00:00 AM"...

    and in addition, your records may have the time part on them,

    that will make them fail in your criteria..

    here's a code( in tsql) if you want to remove the timepart)

    cast(convert(varchar, getutcdate(),112)as datetime)

    i hope that i helped in anyways.. peace out.. ^_^v

  • Anonymous
    1 decade ago

    it looks as if You have only asked for the month of October..if You are wanting a year..You may have to add that to the query.

    *S* Good luck! or You may try reversing the order and asking for records from the month of Nov. thru the month of Oct, 2007..

  • 1 decade ago

    Use this

    Date > 10/?/2007 and Date < 11/?/2007

  • 1 decade ago

    Depends on the RDBMS, some implement a month function, or a function to convert to text. If that is the case, change the date to YYYYMM and do your between.

  • How do you think about the answers? You can sign in to vote the answer.
  • 1 decade ago

    Did you try changing NOV to DEC?

    SELECT *

    FROM SNTPEN

    WHERE (HB_DATE BETWEEN 'OCT 2007' AND 'DEC 2007')

Still have questions? Get your answers by asking now.