bsearch/qsort problem for effective_dated search non-exact

Discussion in 'C Programming' started by c_programmer, Jun 7, 2005.

  1. c_programmer

    c_programmer Guest

    I have a problem.
    There is a effective dated list FAMILY_ACCOUNTS stored in the memory.
    How to achieve the equivalent of the following SQL statement:


    select * from FAMILY_ACCOUNTS FA
    where EFFECTIVE_DATE =
    (select max(EFFECTIVE_DATE) from FAMILY_ACCOUNTS FA2 where
    FA.FAMILY_ACCOUNTS_KEY = FA2.FAMILY_ACCOUNTS_KEY)
    and EFFECTIVE_STATUS ="ACTIVE"
    and EFFECTIVE_DATE <= given_date
    and FAMILY_ACCOUNTS_KEY = given_key

    using bsearch and qsort?
     
    c_programmer, Jun 7, 2005
    #1
    1. Advertising

  2. c_programmer

    Richard Bos Guest

    (c_programmer) wrote:

    > I have a problem.
    > There is a effective dated list FAMILY_ACCOUNTS stored in the memory.
    > How to achieve the equivalent of the following SQL statement:
    >
    > select * from FAMILY_ACCOUNTS FA
    > where EFFECTIVE_DATE =
    > (select max(EFFECTIVE_DATE) from FAMILY_ACCOUNTS FA2 where
    > FA.FAMILY_ACCOUNTS_KEY = FA2.FAMILY_ACCOUNTS_KEY)
    > and EFFECTIVE_STATUS ="ACTIVE"
    > and EFFECTIVE_DATE <= given_date
    > and FAMILY_ACCOUNTS_KEY = given_key
    >
    > using bsearch and qsort?


    That's impossible to answer unless you tell us, quite precisely:
    - how FAMILY_ACCOUNTS is declared, in your C program;
    - what this SQL code does (I can tell that it selects something based on
    a set of requirements, but how, for example, does max() work?);
    - what the correspondence is between the elements of the SQL data set
    and your C objects.

    Richard
     
    Richard Bos, Jun 8, 2005
    #2
    1. Advertising

  3. c_programmer

    c_programmer Guest

    (Richard Bos) wrote in message news:<4all.nl>...
    > (c_programmer) wrote:
    >
    > > I have a problem.
    > > There is a effective dated list FAMILY_ACCOUNTS stored in the memory.
    > > How to achieve the equivalent of the following SQL statement:
    > >
    > > select * from FAMILY_ACCOUNTS FA
    > > where EFFECTIVE_DATE =
    > > (select max(EFFECTIVE_DATE) from FAMILY_ACCOUNTS FA2 where
    > > FA.FAMILY_ACCOUNTS_KEY = FA2.FAMILY_ACCOUNTS_KEY)
    > > and EFFECTIVE_STATUS ="ACTIVE"
    > > and EFFECTIVE_DATE <= given_date
    > > and FAMILY_ACCOUNTS_KEY = given_key
    > >
    > > using bsearch and qsort?

    >
    > That's impossible to answer unless you tell us, quite precisely:
    > - how FAMILY_ACCOUNTS is declared, in your C program;
    > - what this SQL code does (I can tell that it selects something based on
    > a set of requirements, but how, for example, does max() work?);
    > - what the correspondence is between the elements of the SQL data set
    > and your C objects.
    >
    > Richard


    You don't know SQL?
    FAMILY_ACCOUNT is some struct, that have EFFECTIVE_STATUS AC or DE,
    EFFECTIVE_DATE i.e. 20050608 and some key i.e. Account No. For single
    account we can have more then one row let say:

    key1 20050601 AC
    key1 20050603 AC
    key1 20050605 AC
    key1 20050607 DE


    Our bsearch run with key1 and 20050602 should return row from 20050601
    with key1 and 20060606 should return row from 20050605 and with key1
    20050609 shouldn't return anything at all.
     
    c_programmer, Jun 8, 2005
    #3
  4. c_programmer

    Richard Bos Guest

    (c_programmer) wrote:

    > (Richard Bos) wrote in message news:<4all.nl>...
    > > (c_programmer) wrote:
    > >
    > > > select * from FAMILY_ACCOUNTS FA
    > > > where EFFECTIVE_DATE =
    > > > (select max(EFFECTIVE_DATE) from FAMILY_ACCOUNTS FA2 where
    > > > FA.FAMILY_ACCOUNTS_KEY = FA2.FAMILY_ACCOUNTS_KEY)
    > > > and EFFECTIVE_STATUS ="ACTIVE"
    > > > and EFFECTIVE_DATE <= given_date
    > > > and FAMILY_ACCOUNTS_KEY = given_key
    > > >
    > > > using bsearch and qsort?

    > >
    > > That's impossible to answer unless you tell us, quite precisely:
    > > - how FAMILY_ACCOUNTS is declared, in your C program;
    > > - what this SQL code does (I can tell that it selects something based on
    > > a set of requirements, but how, for example, does max() work?);
    > > - what the correspondence is between the elements of the SQL data set
    > > and your C objects.

    >
    > You don't know SQL?


    Only superficially.

    > FAMILY_ACCOUNT is some struct,


    _Some_ struct. Which part of "precisely" didn't you understand? You
    cannot sort "some" struct. You can only sort a specific struct.

    Richard
     
    Richard Bos, Jun 9, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Artie Gold

    Re: bsearch in C

    Artie Gold, Aug 7, 2003, in forum: C Programming
    Replies:
    0
    Views:
    422
    Artie Gold
    Aug 7, 2003
  2. Davy

    Search for the nearest item by bsearch?

    Davy, Jul 24, 2005, in forum: C Programming
    Replies:
    4
    Views:
    465
  3. Replies:
    17
    Views:
    533
    Ben Pfaff
    Sep 16, 2006
  4. 0m

    bsearch problem in my code

    0m, Apr 29, 2010, in forum: C Programming
    Replies:
    8
    Views:
    424
  5. John Butler

    search reg-exp for exact match

    John Butler, Nov 20, 2008, in forum: Ruby
    Replies:
    2
    Views:
    236
    Robert Klemme
    Nov 22, 2008
Loading...

Share This Page