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. Problem with row concatenation [modified]

Problem with row concatenation [modified]

Scheduled Pinned Locked Moved Database
helpdatabase
6 Posts 4 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.
  • P Offline
    P Offline
    Payal_e_m
    wrote on last edited by
    #1

    Hi All, I have a Student table which has 3 fileds:- ID Name PartNo ---------------------- 1 Smith 3 1 Adam 1 1 Samuel 3 2 Gary 1 2 Johnson 2 3 Immanuel 4 3 Ryan 2 3 Irene 1 3 Pete 5 My problem is i need to group students based on IDs and the Name need to be a concatenation of names based on the PartNo in ascending order. The O/p need to be like:- ID Name --------------------------- 1 Adam Smith 2 Gary Johnson 3 Irene Ryan Immanuel Pete I am working with SQL 2000. Hope somebody can help me sort this out. Thanks In Advance. Payal:) -- modified at 22:57 Wednesday 17th October, 2007

    C M 2 Replies Last reply
    0
    • P Payal_e_m

      Hi All, I have a Student table which has 3 fileds:- ID Name PartNo ---------------------- 1 Smith 3 1 Adam 1 1 Samuel 3 2 Gary 1 2 Johnson 2 3 Immanuel 4 3 Ryan 2 3 Irene 1 3 Pete 5 My problem is i need to group students based on IDs and the Name need to be a concatenation of names based on the PartNo in ascending order. The O/p need to be like:- ID Name --------------------------- 1 Adam Smith 2 Gary Johnson 3 Irene Ryan Immanuel Pete I am working with SQL 2000. Hope somebody can help me sort this out. Thanks In Advance. Payal:) -- modified at 22:57 Wednesday 17th October, 2007

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Any particular reason you didn't go with the more traditional FirstName, MiddleNames, Surname format?


      Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

      P 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Any particular reason you didn't go with the more traditional FirstName, MiddleNames, Surname format?


        Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

        P Offline
        P Offline
        Payal_e_m
        wrote on last edited by
        #3

        Hi Colin, I was being given this table(Built by somebodyelse) to get the specified result. Thanks. Payal

        P 1 Reply Last reply
        0
        • P Payal_e_m

          Hi Colin, I was being given this table(Built by somebodyelse) to get the specified result. Thanks. Payal

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          Your database design is really weird. Having separate forename & surname fields would make your query a lot easier.

          Paul Marfleet

          1 Reply Last reply
          0
          • P Payal_e_m

            Hi All, I have a Student table which has 3 fileds:- ID Name PartNo ---------------------- 1 Smith 3 1 Adam 1 1 Samuel 3 2 Gary 1 2 Johnson 2 3 Immanuel 4 3 Ryan 2 3 Irene 1 3 Pete 5 My problem is i need to group students based on IDs and the Name need to be a concatenation of names based on the PartNo in ascending order. The O/p need to be like:- ID Name --------------------------- 1 Adam Smith 2 Gary Johnson 3 Irene Ryan Immanuel Pete I am working with SQL 2000. Hope somebody can help me sort this out. Thanks In Advance. Payal:) -- modified at 22:57 Wednesday 17th October, 2007

            M Offline
            M Offline
            manojm39
            wrote on last edited by
            #5

            I have one solution but dont know the syntax. So telling the logic only. execute the below tsql stmt select * from codeproj order by id,partno asc Result will be like this: 1 Adam 1 1 Samuel 2 1 Smith 3 2 John 1 2 king 2 Now create a cursor, fetch the data and concatinate in a variable also check for the condition ID. You need to write stored procedure for all these.

            P 1 Reply Last reply
            0
            • M manojm39

              I have one solution but dont know the syntax. So telling the logic only. execute the below tsql stmt select * from codeproj order by id,partno asc Result will be like this: 1 Adam 1 1 Samuel 2 1 Smith 3 2 John 1 2 king 2 Now create a cursor, fetch the data and concatinate in a variable also check for the condition ID. You need to write stored procedure for all these.

              P Offline
              P Offline
              Payal_e_m
              wrote on last edited by
              #6

              Thanks for the reply. I will try it out.

              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