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. Transposing rows and Columns in SQL

Transposing rows and Columns in SQL

Scheduled Pinned Locked Moved Database
databasequestion
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 MQ-SQL 2005 stored procedure that returns a dataset that is fine except I would like to change the rows to the columns and the columns into the rows. Is there an easy command to do this, or is pivot the only option (which is not easy)? Thanks,

    Leo T. Smith Program/Analyst Supervisor

    N 1 Reply Last reply
    0
    • L Leo Smith

      I have a MQ-SQL 2005 stored procedure that returns a dataset that is fine except I would like to change the rows to the columns and the columns into the rows. Is there an easy command to do this, or is pivot the only option (which is not easy)? Thanks,

      Leo T. Smith Program/Analyst Supervisor

      N Offline
      N Offline
      Niladri_Biswas
      wrote on last edited by
      #2

      Hi, This kind of problems are called Cross Tab Queries and can be solved easily using PIVOTING (a feature from SQL SERVER 2005+). Here is an example Pivots with Dynamic Columns in SQL Server 2005[^] You can even look into a) Cross-Tab reports in SQL Server 2005[^] b)Using PIVOT and UNPIVOT[^] In Sql Server 2000, Pivoting was achieved using Case along with an aggregate function. Look here Pivot Table Data in SQL Server 2000 and 2005[^] However, a few days back I gave a similar kind of answer in Bytes. U can have a look Month to month yearly results[^] Hope this helps :)

      Niladri Biswas

      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