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. Converting rows into columns (PIVOT for string values)

Converting rows into columns (PIVOT for string values)

Scheduled Pinned Locked Moved Database
helpdatabasequestion
2 Posts 2 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.
  • L Offline
    L Offline
    Leo Smith
    wrote on last edited by
    #1

    I have a small problem. I need to convert some rows into columns. Look at the following information. Original Table: Ind Sub String 0 1 22 0 2 21 0 3 5.6 0 4 John Rogers 1 1 12 1 2 76 1 3 99.3 1 4 Sarah Peters Converted to: Ind val1 val2 val3 val4 0 22 21 5.6 John Rogers 1 12 76 99.3 Sarah Peters This is similar to a pivot, except that I am not count, averaging, counting, or any other agregating methods. Is there a simple query that will convert this or is this going to be a cursor issue?

    Leo T. Smith Program/Analyst Supervisor

    M 1 Reply Last reply
    0
    • L Leo Smith

      I have a small problem. I need to convert some rows into columns. Look at the following information. Original Table: Ind Sub String 0 1 22 0 2 21 0 3 5.6 0 4 John Rogers 1 1 12 1 2 76 1 3 99.3 1 4 Sarah Peters Converted to: Ind val1 val2 val3 val4 0 22 21 5.6 John Rogers 1 12 76 99.3 Sarah Peters This is similar to a pivot, except that I am not count, averaging, counting, or any other agregating methods. Is there a simple query that will convert this or is this going to be a cursor issue?

      Leo T. Smith Program/Analyst Supervisor

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Use Max(stringvalue) for your aggregate function (you are after all aggregating 1 value), you can see an example here[^]

      Never underestimate the power of human stupidity RAH

      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