Puzzle: Possible Combinations (yet another)

  • Hi All,

    I have parts catalogue with part codes that can be parsed to determine the part features.  The structure of the code is something like this:

    XXXX-F1-F2-F3-F4-...Fn

    where F1 through Fn describe features of part XXXX.

    The number of features parts have can changes as the catalogue grows:  Today a part may have a color and shape (F1, F2).  Tomorrow it may have a colour, shape, and weight (F1, F2, F3).

    A table stores all possible feature-value combinations (in two columns): 

    E.g., color-blue, color-red, color-green, shape-round,  shape-square;

    The challenge:  Provide an algorithm that will return the possible part codes based on the current feature-value records.

    In the above example, the correct query will return:

    blue-round, blue-square, red-round, red-square, green-round, green-square

    (Note: I am ignoring the partcode itself, xxxx).

    Thanks for any suggestions.

    Sean

  • This was removed by the editor as SPAM

  • Here is a really feeble friday afternoon starter for 10...

    If you only had two features, then you could create a cross join between two copies of the table, one copy returning a distinct set of colours, the other a distinct set of shapes. the cartesian product would produce all combinations of colour and shape.

    The problem of course is that each new feature requires a further copy of the table returning its particular feature.

    No doubt the dynamic SQL aficionados could create an SP that generated a dynamic statement with a copy of the table for each feature...

    David

    If it ain't broke, don't fix it...

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

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