Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 checking for a total against all combinations of a column

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-21 : 08:48:43
assim writes "Hi Guys,

I am trying to check if a figure(taken from another table) is equal to the sum of all combinations of a column in a table.

E.g. figure is 10 , table to check:-

Id Value (could be any number)
1 2
2 5
3 1
4 4

So want to check all combinations until i find a match and stop or keep looking until all combinations checked.

i.e. 2,5,1,4,2+5,2+5+1,2+5+1+4,2+1,2+1+4,2+5+4 etc

In this case there is a match - 5+1+4 = 10

This is the simple problem, but i could apply the solution to loop through a number of total figures and check for matching combo's as i am able to identify all rows that can be combined just not sure how to get all combinations and speed will be an issue. - Over to you. Many Thanks."
   

- Advertisement -