Thanks for your help.
I am looking for a way to get distinct list of number permutations for the following result set.
This is what is given
ID+keyID is unqiueID+Seq is unique. Seq can be <= 10
Seq is incrementing integer value
DECLARE @t TABLE (ID int, keyID int, Seq int) INSERT @t VALUES (1, 10, 1) ,(1, 11, 2) ,(1, 12, 3) ,(2, 20, 1) ,(2, 21, 2) SELECT * FROM @t -- How do I make from the above data set result below? -- result set needed
-- result set needed SELECT * FROM (VALUES (1, 10, 1, 1) ,(1, 11, 2, 1) ,(1, 12, 3, 1) -- ,(1, 10, 1, 2) ,(1, 11, 2, 2) -- ,(1, 10, 1, 3) ,(1, 12, 3, 3) -- ,(1, 11, 2, 4) ,(1, 12, 3, 4) ,(1, 10, 1, 5) -- ,(1, 12, 3, 6) -- ,(1, 12, 3, 7) -- ,(2, 20, 1, 1) ,(2, 21, 2, 1) -- ,(2, 20, 1, 2) -- ,(2, 21, 2, 3) ) v (ID, keyID, Seq, grpID)
PS.
this almost gives me what I want but
SELECT * FROM @t t JOIN(VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)) as n(N) ON n.N < t.Seq ORDER BY t.ID, n.N
Vladimir Moldovanenko