possible combinations in int column for given value

  • I have a table with Int Column, sample table with data like bellow

    ItemID, Name, Quantity

    ------------------

    1 A 2

    2 B 1

    3 C 3

    4 D 4

    5 E 5

    so I need to write a query to return all possible combinations with matching Quantity column.

    E.G. if I passed 8

    need result set like bellow (2+1+5 = 8, 3+5 = 8, 1,3,4 = 8)

    combinationID, Quantity, NoOfItems

    1 2 3

    1 1 3

    1 5 3

    2 3 2

    2 5 2

    3 1 3

    3 3 3

    3 4 3

    advice me

  • What have you tried so far and where do you get stuck?



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • You're going to need to recursively cross-join the table with itself, essentially.

    This question is almost always school work. Is it this time, too?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply