Find the matching total Qty in SQL Server -


need here, below sample data need find matching request qty. let's request qty 90. in query can auto search possibility of matching total sum qty.

for example, results can possible combination ids:-

  1. 2 + 10 = 90
  2. 3 + 8 = 90
  3. 5 + 6 = 90
  4. 4 + 7 = 90
  5. 6 + 7 + 8 = 90 . . .

i understand combination formula can doing in sql server, n!/(n-r)!(r!). can slowdown query execution time if have thousand of rows need find qty matching.

but want find first match qty enough instead of generate entire list of combination possibility.

in case, have ideas or sample query can making query run faster on above scenario besides combination?

+----+----------+-----+ | id | material | qty | +----+----------+-----+ |  1 |        |  90 | |  2 |        |  80 | |  3 |        |  70 | |  4 |        |  60 | |  5 |        |  50 | |  6 |        |  40 | |  7 |        |  30 | |  8 |        |  20 | |  9 |        |  20 | | 10 |        |  10 | +----+----------+-----+ 


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -