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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Transpose in SQL 2k5

Transpose in SQL 2k5

Scheduled Pinned Locked Moved Database
databasequestion
6 Posts 3 Posters 0 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.
  • A Offline
    A Offline
    Abdul Rahman Hamidy
    wrote on last edited by
    #1

    Dear All, I have bellow table which I want to transpose, the pivot in SQL 2k5 works but I want it like in a dynamic way. as lets say i have table EmpID Name 1 A 2 B I want to transpose by EmpID, that works fine but what if one more record is added to the table as EmpID Name 1 A 2 B 3 C then my transpose only picks up 1 and 2, how can i dynamically transpose that?

    Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

    P H 2 Replies Last reply
    0
    • A Abdul Rahman Hamidy

      Dear All, I have bellow table which I want to transpose, the pivot in SQL 2k5 works but I want it like in a dynamic way. as lets say i have table EmpID Name 1 A 2 B I want to transpose by EmpID, that works fine but what if one more record is added to the table as EmpID Name 1 A 2 B 3 C then my transpose only picks up 1 and 2, how can i dynamically transpose that?

      Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

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

      I do that in a DataTable once I've read the data, you could also do it while reading the data. I've never had a need for doing that in the database.

      A 1 Reply Last reply
      0
      • A Abdul Rahman Hamidy

        Dear All, I have bellow table which I want to transpose, the pivot in SQL 2k5 works but I want it like in a dynamic way. as lets say i have table EmpID Name 1 A 2 B I want to transpose by EmpID, that works fine but what if one more record is added to the table as EmpID Name 1 A 2 B 3 C then my transpose only picks up 1 and 2, how can i dynamically transpose that?

        Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

        H Offline
        H Offline
        Hiren solanki
        wrote on last edited by
        #3

        I hope you are asking about dynamic column generation with PIVOT. You can first generate all the column dynamically using SQL Query and then you can give as a column input to PIVOT that will work beyond the static column bounary. You could find THIS[^] to be useful.

        Regards, Hiren.

        My Recent Article: - Way to know which control have raised a postback
        My Recent Tip/Trick: - The ?? Operator.

        modified on Monday, December 27, 2010 2:51 AM

        A 1 Reply Last reply
        0
        • P PIEBALDconsult

          I do that in a DataTable once I've read the data, you could also do it while reading the data. I've never had a need for doing that in the database.

          A Offline
          A Offline
          Abdul Rahman Hamidy
          wrote on last edited by
          #4

          thanks for your reply, doing in DataTable is the simplest solution.

          Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

          1 Reply Last reply
          0
          • H Hiren solanki

            I hope you are asking about dynamic column generation with PIVOT. You can first generate all the column dynamically using SQL Query and then you can give as a column input to PIVOT that will work beyond the static column bounary. You could find THIS[^] to be useful.

            Regards, Hiren.

            My Recent Article: - Way to know which control have raised a postback
            My Recent Tip/Trick: - The ?? Operator.

            modified on Monday, December 27, 2010 2:51 AM

            A Offline
            A Offline
            Abdul Rahman Hamidy
            wrote on last edited by
            #5

            appreciated, that is what i need!

            Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

            H 1 Reply Last reply
            0
            • A Abdul Rahman Hamidy

              appreciated, that is what i need!

              Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

              H Offline
              H Offline
              Hiren solanki
              wrote on last edited by
              #6

              Glad it helped you.

              Regards, Hiren.

              My Recent Article: - Way to know which control have raised a postback
              My Recent Tip/Trick: - The ?? Operator.

              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