Solved

create a semicolon delimeted list

Posted on 2016-09-08
1
40 Views
Last Modified: 2016-09-08
I am trying to write a select statement  which will return a semicolon delimeted list. Here is what I want.

Currently my select statement is returning me the following resultset

userroleid          childuserroleid
   4                               4
   4                             10
   4                               7
   8                             12
   8                              13
   8                              15
   11                             44
    12                            89

I want the select statement to return following

userroleid          childuserroleid
   4                               4;10;7
   8                             12;13;15
   11                             44
    12                            89


Thanks
0
Comment
Question by:PratikShah111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41789735
Use STUFF function together with FOR XML PATH output:
SELECT  userroleid,
          STUFF((SELECT ',' + childuserroleid
                    FROM TableName T2
                    WHERE T2.userroleid = T1.userroleid
                    FOR XML PATH('') ), 1, 1, '' )
            AS ConcatenatedText
FROM  TableName T1

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question