Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    8

    Unanswered: Select statement for date range

    Dear all,

    If I have a customer table, inside got a column named DOB, How can I write a Select statement that query the customer that born on let say
    between Jan 13 and Feb 12?

    Let say the table look like below

    CusId Custname DOB
    1 Cust A 1/1/1977
    2 Cust B 2/2/1966
    3 Cust C 3/3/1988
    4 Cust D 4/4/1999
    5 Cust E 5/5/1955

    Thnks and have a nice day.

    Regards,
    Joon Ping.

  2. #2
    Join Date
    Sep 2003
    Posts
    8
    any one do this kind of query before?

    Regards,
    Joon Ping.

  3. #3
    Join Date
    Sep 2003
    Location
    Germany
    Posts
    63
    Hello!

    First I would convert the date of birth into ISO-format (YYYYMMDD). The next step would be to take only day and month and compare this string with your begin and end date of your date range.

    A sample code could be:
    Code:
    select right(convert(varchar, dob, 112), 4) as mmdd
    from dbo.table
    where right(convert(varchar, dob, 112), 4) between '0113' and '0212'
    Hope this helps you out!

    Greetings,
    Carsten

  4. #4
    Join Date
    Sep 2003
    Posts
    8
    Dear Carsten,

    So nice of you, thank you very much.
    the query working perfectly this time in query analyser.

    I still need to migrade them into delphi...

    I owe you a favor! So next time come to Malaysia remember to give me an email o...

    Good Luck and have a nice day.

    Regards,
    Joon Ping.

Posting Permissions

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