bsearch/qsort problem for effective_dated search non-exact

C

c_programmer

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?
 
R

Richard Bos

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
 
C

c_programmer

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top