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. PIVOT

PIVOT

Scheduled Pinned Locked Moved Database
help
5 Posts 5 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.
  • M Offline
    M Offline
    Mugdha_Aditya
    wrote on last edited by
    #1

    I have a table with only one column as Emp_Name A B C D E I want to display this data as Emp_Name A, B, C, D, E Please help me as soon as possible

    J L N N 4 Replies Last reply
    0
    • M Mugdha_Aditya

      I have a table with only one column as Emp_Name A B C D E I want to display this data as Emp_Name A, B, C, D, E Please help me as soon as possible

      J Offline
      J Offline
      JHizzle
      wrote on last edited by
      #2

      I'm not sure I understand, could you elaborate please? It looks like you're wanting to merge every record in a table into one? That's sort of anti-database design, no?

      1 Reply Last reply
      0
      • M Mugdha_Aditya

        I have a table with only one column as Emp_Name A B C D E I want to display this data as Emp_Name A, B, C, D, E Please help me as soon as possible

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Mugdha_Aditya wrote:

        Please help me as soon as possible

        Start here[^] :)

        I are Troll :suss:

        1 Reply Last reply
        0
        • M Mugdha_Aditya

          I have a table with only one column as Emp_Name A B C D E I want to display this data as Emp_Name A, B, C, D, E Please help me as soon as possible

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

          Try this declare @t table(Emp_Name varchar(50)) insert into @t select 'A' union all select 'B' union all select 'C' union all select 'D' union all select 'E' Solution 1: declare @concat varchar(100) set @concat = '' select @concat = @concat + Emp_Name + ',' from @t select Emp_Name =Left(@concat,len(@concat)-1) Solution 2: select Emp_Name = RIGHT(delimitedCol,len(delimitedCol)-1) from (select ',' + CAST(Emp_Name AS varchar(8000)) from @t for xml path(''))x(delimitedCol) Output(For both the cases)**

          Emp_Name
          A,B,C,D,E

          **Even you can use while loop , cursors but the approaches mentioned above are faster enough. :)

          Niladri Biswas

          1 Reply Last reply
          0
          • M Mugdha_Aditya

            I have a table with only one column as Emp_Name A B C D E I want to display this data as Emp_Name A, B, C, D, E Please help me as soon as possible

            N Offline
            N Offline
            nainakarri
            wrote on last edited by
            #5

            Can i know the reason why you want to use Pivot? Using For XML PATH('') also you can get the same result. select emp_name + ', ' from tabble where condition for xml path('') Regards Naina

            Naina

            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