question

Qrosh avatar image
Qrosh asked

sql query permutations without repetition

I need a query which can be used in (or as) a function and retrieves all permutations of n values. And I need all permutations of length k where k = 1..n. Extended sample input and result so input has 3 values instead of 2 - however, number of input values may vary from 1 to n. Example: Input: table with values in one column in multiple rows Value (nvarchar(500)) ------ Ann John Mark Output#1: table with values concatenated in one column Ann John Mark Ann,John Ann,Mark John,Mark Ann,John,Mark
sql-server-2012transactionpermutations
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
You might want to start by having a look at am old speed phreak contest that does permutations... http://ask.sqlservercentral.com/questions/3045/the-word-permutation-sql-problem.html
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kevin Feasel avatar image
Kevin Feasel answered
[Paul White's answers to this exact question][1]. I doubt I could add anything to his explanation. [1]: http://dba.stackexchange.com/a/29666/14907
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.