Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Generate combinations for series

Generate combinations for series

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelptutorial
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 2769284
    wrote on last edited by
    #1

    declare @a varchar(500) set @a = '1,2,3,4' how to generate output for all the combinations of input @a like 1,2,3,4 ; 1,2,4,3 ; 1,3,2,4 ; 1,3,4,2 ; 1,4,2,3 ; 1,4,3,2 ; 2,1,3,4; 2,1,4,3 ; 2,3,1,4... All the numbers will be in series like for 10 digits.. 1,2,3,4,5,6,7,8,9,10. i require all the combinations to be generated. the series i found like in the input if last (N) and last-1 (N-1) digits are interchanged, in series 1,2,3,4, second sequence wil be 1,2,4,3 ( interchange last two digits). next 1,3,2,4(N-3 digit is incremented and missing numbers 2,4 are placed).Next sequence wil be 1,3,4,2 ( interchange last two digits).. it could give all the combinations. Could some one help me in providing solution for this. while i am using sql server 2005. thanks in advance, rpp

    H 1 Reply Last reply
    0
    • U User 2769284

      declare @a varchar(500) set @a = '1,2,3,4' how to generate output for all the combinations of input @a like 1,2,3,4 ; 1,2,4,3 ; 1,3,2,4 ; 1,3,4,2 ; 1,4,2,3 ; 1,4,3,2 ; 2,1,3,4; 2,1,4,3 ; 2,3,1,4... All the numbers will be in series like for 10 digits.. 1,2,3,4,5,6,7,8,9,10. i require all the combinations to be generated. the series i found like in the input if last (N) and last-1 (N-1) digits are interchanged, in series 1,2,3,4, second sequence wil be 1,2,4,3 ( interchange last two digits). next 1,3,2,4(N-3 digit is incremented and missing numbers 2,4 are placed).Next sequence wil be 1,3,4,2 ( interchange last two digits).. it could give all the combinations. Could some one help me in providing solution for this. while i am using sql server 2005. thanks in advance, rpp

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      I do not have an answer in T-SQL or SQL but here[^] is a link to a C# recursive algorithm that you might find useful.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      P 1 Reply Last reply
      0
      • H Henry Minute

        I do not have an answer in T-SQL or SQL but here[^] is a link to a C# recursive algorithm that you might find useful.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Ew, recursion is not necessary for this, but I agree that SQL isn't the right tool.

        U 1 Reply Last reply
        0
        • P PIEBALDconsult

          Ew, recursion is not necessary for this, but I agree that SQL isn't the right tool.

          U Offline
          U Offline
          User 2769284
          wrote on last edited by
          #4

          but my requirement is, i need to work on sql server 2005 only.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups