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. Can the Pivot operator be used with text columns?

Can the Pivot operator be used with text columns?

Scheduled Pinned Locked Moved Database
databasesql-serversysadmindata-structurestutorial
5 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.
  • Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #1

    I am new to the Pivot operator in SQL Server. I see that the Pivot operator requires an aggregate function in order to work. However, I need to pivot a text column, and I can't find any examples that show how to do it. Am I barking up the wrong tree, or is there a way to pivot a text column?

    The difficult we do right away... ...the impossible takes slightly longer.

    Richard DeemingR J 2 Replies Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      I am new to the Pivot operator in SQL Server. I see that the Pivot operator requires an aggregate function in order to work. However, I need to pivot a text column, and I can't find any examples that show how to do it. Am I barking up the wrong tree, or is there a way to pivot a text column?

      The difficult we do right away... ...the impossible takes slightly longer.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      There are a few aggregate operators the work on varchar columns - for example, Max. sql - PIVOT with varchar datatype - Stack Overflow[^] sql server - Pivot Table with varchar values - Stack Overflow[^] SQL Server pivoting on non-numeric data types - SQL Shack[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      Richard Andrew x64R 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        I am new to the Pivot operator in SQL Server. I see that the Pivot operator requires an aggregate function in order to work. However, I need to pivot a text column, and I can't find any examples that show how to do it. Am I barking up the wrong tree, or is there a way to pivot a text column?

        The difficult we do right away... ...the impossible takes slightly longer.

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #3

        As long as you never have more than one value per row and column it doesn't matter very much which function you use as long as it works with text. (Min, Max or user defined). But depending on your data it might be possible to get more than one value per cell, then you need to choose what to show. That's what the aggregate function is for.

        Wrong is evil and must be defeated. - Jeff Ello

        Richard Andrew x64R 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          There are a few aggregate operators the work on varchar columns - for example, Max. sql - PIVOT with varchar datatype - Stack Overflow[^] sql server - Pivot Table with varchar values - Stack Overflow[^] SQL Server pivoting on non-numeric data types - SQL Shack[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          Thank you, Richard.

          The difficult we do right away... ...the impossible takes slightly longer.

          1 Reply Last reply
          0
          • J Jorgen Andersson

            As long as you never have more than one value per row and column it doesn't matter very much which function you use as long as it works with text. (Min, Max or user defined). But depending on your data it might be possible to get more than one value per cell, then you need to choose what to show. That's what the aggregate function is for.

            Wrong is evil and must be defeated. - Jeff Ello

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            Thank you Jörgen.

            The difficult we do right away... ...the impossible takes slightly longer.

            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