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 two or more rows single string in SQL

Concatenate two or more rows single string in SQL

Scheduled Pinned Locked Moved Database
databasesql-serversysadminxml
4 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.
  • S Offline
    S Offline
    Sunasara Imdadhusen
    wrote on last edited by
    #1

    Hi I would like to share cool feature of SQL Server with you guys like: Please use the following query when concatenate two or more rows with comma (or any you want) in a single string.

    SELECT STUFF((SELECT ',' + RTRIM(RegionDescription) FROM Region FOR XML PATH('')),1,1,'') AS 'Regions'

    Please do let me know, if you have any doubt. Please provide "Vote" if this would be helpful.:rose: Thanks, Imdadhusen

    sunaSaRa Imdadhusen +91 99095 44184 +91 02767 284464

    B M 2 Replies Last reply
    0
    • S Sunasara Imdadhusen

      Hi I would like to share cool feature of SQL Server with you guys like: Please use the following query when concatenate two or more rows with comma (or any you want) in a single string.

      SELECT STUFF((SELECT ',' + RTRIM(RegionDescription) FROM Region FOR XML PATH('')),1,1,'') AS 'Regions'

      Please do let me know, if you have any doubt. Please provide "Vote" if this would be helpful.:rose: Thanks, Imdadhusen

      sunaSaRa Imdadhusen +91 99095 44184 +91 02767 284464

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Good stuff. :)


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      1 Reply Last reply
      0
      • S Sunasara Imdadhusen

        Hi I would like to share cool feature of SQL Server with you guys like: Please use the following query when concatenate two or more rows with comma (or any you want) in a single string.

        SELECT STUFF((SELECT ',' + RTRIM(RegionDescription) FROM Region FOR XML PATH('')),1,1,'') AS 'Regions'

        Please do let me know, if you have any doubt. Please provide "Vote" if this would be helpful.:rose: Thanks, Imdadhusen

        sunaSaRa Imdadhusen +91 99095 44184 +91 02767 284464

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

        Publish it as a tip/trick, that way people who are looking for it will find it. Your main audience here are people looking to help others and probably already know this method.

        Never underestimate the power of human stupidity RAH

        S 1 Reply Last reply
        0
        • M Mycroft Holmes

          Publish it as a tip/trick, that way people who are looking for it will find it. Your main audience here are people looking to help others and probably already know this method.

          Never underestimate the power of human stupidity RAH

          S Offline
          S Offline
          Sunasara Imdadhusen
          wrote on last edited by
          #4

          Thanks for your suggestions, i will be share this on Tips/Tricks sections

          sunaSaRa Imdadhusen +91 99095 44184 +91 02767 284464

          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