[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Generate unique combinations/permutation

Asked by krogstruphede in MS SQL Server, SQL Server 2008, MS SQL DTS

My setup is as follows:

Tbl: Listtype (can contain n types)
ID*  Type
--------------
1    Color
2    Size
3    Quality

Tbl: ListOptions (can contain n options)
ID, TypeID, Option
---------------------------
1  1  Red
2  1  Blue
3  2  Smal
4  2  Large
5  3  Low
6  3  High

Now i want to add a new product, that uses some - or all - of the lists/options
(ie product 1 might have 4 colors, 3 sizes and no quality assignment, product 2 might have 2 colors, 4 sizes and 3 qualities)

If a products uses all lists/options from above, it would generate 8 combinations (2x2x2)
And i need following rows to be generated:

Tbl: Variants (Unique variantID, productID and additions data specifik for the variant)
-------------------------------
ID ProductID
1  1
2  1
3  1
4  1
5  1
6  1
7  1
8  1
(This one i have already sorted out, but maybe it needs to be generated in conjunction with the following)

Tbl: VariantOptions
ID*  VariantID, OptionID
1   1  1
2   1  3
3   1  5
4   2  1
5   2  3
6   2  6
7   3  1
8   3  4
9   3  5
10  4  1
11  4  4
12  4  6
13  5  2
14  5  3
15  5  5
16  6  2
17  6  3
18  6  6
19  7  2
20  7  4
21  7  5
22  8  2
23  8  4
24  8  6

Im dealing with a large number of combinations, so if possible i would like to avoid cursors/while ect.

Any thoughts is appreciated
[+][-]11/04/09 08:43 AM, ID: 25741184Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:36 AM, ID: 25747866Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 01:51 AM, ID: 25747938Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 01:58 PM, ID: 25763449Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625