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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUERY/ MATH FORMULA PROCEDURE NEEDED

Status
Not open for further replies.

cdw0308

Technical User
Oct 8, 2003
181
US
I am trying to make a query to pick numbers out of a table of several numbers that equals my end result which is known already. There are much more numbers in my number table that will not be used. The hard part is finding the correct numbers to add up to the total. There is negative numbers and positive numbers in the table.

Example:
I know my end result is 25,754.01
I have a table that contains several numbers which i need a query to pull out the numbers that add together to equal the 25,754.01

I know that with the correct numbers applied it will equal up to my end result. I just have too many numbers to set and go through all the scenarios

Is there a way to take my table of numbers and run through a procedure to come up with my end result??

 
Code:
select t1.n as x
     , t2.n as y
  from daTable as t1
     , daTable as t2
 where t1.n + t2.n = 25,754.01 
   and t1.n > t2.n
if this yields nothing, try again with a 3-way self-join, then 4...

r937.com | rudy.ca
 
thanks so much,
the 2 way did not work
What would the code look like for 3 or 4

Thanks
 
Code:
select t1.n as x
     , t2.n as y
     [blue], t3.n as z[/blue]
  from daTable as t1
     , daTable as t2
     [blue], daTable as t3[/blue]
 where t1.n + t2.n [blue]+ t3.n[/blue] = 25754.01 
   and t1.n > t2.n
   [blue]and t2.n > t3.n[/blue]
caution: this will get very slow as you cross-join more copies of the table

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top