Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to get query to generate distinct list of number permutations?

$
0
0

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 unqiue

ID+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





Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>