Michael J. Swart uses a recursive common table expression and bit shifting to build a full set of permutations:
If you google “generating permutations using SQL”, you get thousands of hits. It’s an interesting problem if not very useful.
I wrote a solution recently and thought I’d share it. If you’re keen, try tackling it yourself before moving on.
Click through for the script. It’s an interesting approach and might be worth playing a round of code golf.