Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

urgent-- please help

Status
Not open for further replies.

557

Programmer
Oct 25, 2004
64
US
can someone please help me with this problem

i have a table with about 1000 records. each record has many detail fields and an amount field. when the user gives a particular amount ,say 10000, i want to find all combinations of records in this table which will give me a sum of exactly this amount 10000. there may be 1 record or 2 records or 3 records or n records that give me this amount as sum. how do i get all the combinations in this table for this requirement?
 
You could start by selecting all rows from the table where AMOUNT <= 10000, which will at least exclude any rows where the amount is too big to start with. Then you need to come up with an algorithm to find all the combinations (not permutations) that match.

Is this just an intellectual exercise, or do you have a business requirement to satisfy? It's just that this looks a bit like an NP-complete travelling salesman type problem, so don't expect it to be easy...
 
not an intellectual exercise. there is a requirement. i've come up with an algorithm. i'll get back if it doesn't work as expected
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top