CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2005
    Posts
    70

    oracle query help

    Patient table:


    Patient Number Name DOB
    --------- ------------- -----------
    P32423 Joe bloggs 4-feb-78
    P11123 Katy smith 6-jun-97
    P03923 Jacob halls 16-dec


    need a query to display patients that are under 18. any help?

  2. #2
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: oracle query help

    Code:
     SELECT * FROM Patients where ADD_MONTHS(DOB,12*18)>SYSDATE
    Hope that it helps.

  3. #3
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309

    Re: oracle query help

    Actually should be

    SELECT * FROM Patients where ADD_MONTHS(DOB,12*18)>=SYSDATE

  4. #4
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: oracle query help

    Actually should be
    Actually not necessery .

  5. #5
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: oracle query help

    Code:
    SELECT * FROM Patients WHERE ADD_MONTHS(DOB,216)>=TRUNC(SYSDATE)
    antares686:
    your solution makes no important difference .
    It is common error made by begginers - SYSDATE contains hour, minute etc. and date of birth usually NOT.

    And it depends on customs/regional rules if man in date of his birth is considered that he is under age or not (it is often stated that he have to has finished 18 years - that he has to be 18+)
    Hope U understand what I wrote .

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured