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. Concatenate names from all all the rows to one column

Concatenate names from all all the rows to one column

Scheduled Pinned Locked Moved Database
help
9 Posts 6 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
    member27
    wrote on last edited by
    #1

    Hi all, I want to get concatenatenames of all rows in one column ..can any one help me. suppose i get A B C AS 3 3 DIFFERENT ROWS I WANT TO CONCATENATE GET ABC AS THE RESULT = NEW COLUMN.. CAN ANY ONE CAN HELP

    W K R 3 Replies Last reply
    0
    • M member27

      Hi all, I want to get concatenatenames of all rows in one column ..can any one help me. suppose i get A B C AS 3 3 DIFFERENT ROWS I WANT TO CONCATENATE GET ABC AS THE RESULT = NEW COLUMN.. CAN ANY ONE CAN HELP

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      An easy way would be writing a stored procedure, opening a cursor on the table, loop through it and while looping, concatenate the return string.

      The need to optimize rises from a bad design.My articles[^]

      M 1 Reply Last reply
      0
      • M member27

        Hi all, I want to get concatenatenames of all rows in one column ..can any one help me. suppose i get A B C AS 3 3 DIFFERENT ROWS I WANT TO CONCATENATE GET ABC AS THE RESULT = NEW COLUMN.. CAN ANY ONE CAN HELP

        K Offline
        K Offline
        Khawar Abbas1
        wrote on last edited by
        #3

        You can use COALESCE function of sql server for this purpose.

        Do good and have good.

        R 1 Reply Last reply
        0
        • M member27

          Hi all, I want to get concatenatenames of all rows in one column ..can any one help me. suppose i get A B C AS 3 3 DIFFERENT ROWS I WANT TO CONCATENATE GET ABC AS THE RESULT = NEW COLUMN.. CAN ANY ONE CAN HELP

          R Offline
          R Offline
          Rob Philpott
          wrote on last edited by
          #4

          Something like this:

          create table #X
          (
          C char(1)
          )

          insert into #X values ('A')
          insert into #X values ('B')
          insert into #X values ('C')

          declare @z as varchar(2000)
          set @z = ''

          select @z = @z + C from #X

          select @z

          drop table #x

          yields: ABC

          Regards, Rob Philpott.

          M 1 Reply Last reply
          0
          • K Khawar Abbas1

            You can use COALESCE function of sql server for this purpose.

            Do good and have good.

            R Offline
            R Offline
            Rob Philpott
            wrote on last edited by
            #5

            You reckon? How exactly?

            Regards, Rob Philpott.

            1 Reply Last reply
            0
            • R Rob Philpott

              Something like this:

              create table #X
              (
              C char(1)
              )

              insert into #X values ('A')
              insert into #X values ('B')
              insert into #X values ('C')

              declare @z as varchar(2000)
              set @z = ''

              select @z = @z + C from #X

              select @z

              drop table #x

              yields: ABC

              Regards, Rob Philpott.

              M Offline
              M Offline
              member27
              wrote on last edited by
              #6

              Thank u verymuch it worked fine...

              1 Reply Last reply
              0
              • W Wendelius

                An easy way would be writing a stored procedure, opening a cursor on the table, loop through it and while looping, concatenate the return string.

                The need to optimize rises from a bad design.My articles[^]

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

                I hate cursors so I love this concat function DECLARE @Text VARCHAR(8000) SET @Text = '' SELECT @Text = @Text + ',' + class FROM PFClass SELECT @Text

                Never underestimate the power of human stupidity RAH

                J W 2 Replies Last reply
                0
                • M Mycroft Holmes

                  I hate cursors so I love this concat function DECLARE @Text VARCHAR(8000) SET @Text = '' SELECT @Text = @Text + ',' + class FROM PFClass SELECT @Text

                  Never underestimate the power of human stupidity RAH

                  J Offline
                  J Offline
                  Jon_Boy
                  wrote on last edited by
                  #8

                  Agreed......much rather use WHILE EXISTS(

                  Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                  1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    I hate cursors so I love this concat function DECLARE @Text VARCHAR(8000) SET @Text = '' SELECT @Text = @Text + ',' + class FROM PFClass SELECT @Text

                    Never underestimate the power of human stupidity RAH

                    W Offline
                    W Offline
                    Wendelius
                    wrote on last edited by
                    #9

                    Yeah, also thought it was neat.

                    The need to optimize rises from a bad design.My articles[^]

                    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