get a comma delimited string from rows [duplicate]











up vote
1
down vote

favorite













This question already has an answer here:




  • How to concatenate text from multiple rows into a single text string in SQL server?

    44 answers




What will be the query in MS Sql Server to concatenate my rows in one string , delimited by comma (Like shown below)



query to delimeter string










share|improve this question















marked as duplicate by krokodilko, Shnugo sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 22 '17 at 10:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Which DBMS are you using? Oracle or SQL Server? And Have you tried something?
    – JSapkota
    Jan 22 '17 at 6:06










  • SQL SERVER, i have no idea how to do.....
    – Ajit Kumar
    Jan 22 '17 at 6:33






  • 1




    Please have a look here stackoverflow.com/q/194852/1530987
    – bhageena
    Jan 22 '17 at 6:46










  • Please read How to Ask.
    – Zohar Peled
    Jan 22 '17 at 8:07















up vote
1
down vote

favorite













This question already has an answer here:




  • How to concatenate text from multiple rows into a single text string in SQL server?

    44 answers




What will be the query in MS Sql Server to concatenate my rows in one string , delimited by comma (Like shown below)



query to delimeter string










share|improve this question















marked as duplicate by krokodilko, Shnugo sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 22 '17 at 10:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Which DBMS are you using? Oracle or SQL Server? And Have you tried something?
    – JSapkota
    Jan 22 '17 at 6:06










  • SQL SERVER, i have no idea how to do.....
    – Ajit Kumar
    Jan 22 '17 at 6:33






  • 1




    Please have a look here stackoverflow.com/q/194852/1530987
    – bhageena
    Jan 22 '17 at 6:46










  • Please read How to Ask.
    – Zohar Peled
    Jan 22 '17 at 8:07













up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:




  • How to concatenate text from multiple rows into a single text string in SQL server?

    44 answers




What will be the query in MS Sql Server to concatenate my rows in one string , delimited by comma (Like shown below)



query to delimeter string










share|improve this question
















This question already has an answer here:




  • How to concatenate text from multiple rows into a single text string in SQL server?

    44 answers




What will be the query in MS Sql Server to concatenate my rows in one string , delimited by comma (Like shown below)



query to delimeter string





This question already has an answer here:




  • How to concatenate text from multiple rows into a single text string in SQL server?

    44 answers








sql sql-server sql-server-2012






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 22 '17 at 8:58









Hadi

16.3k62570




16.3k62570










asked Jan 22 '17 at 5:58









Ajit Kumar

1513




1513




marked as duplicate by krokodilko, Shnugo sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 22 '17 at 10:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by krokodilko, Shnugo sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 22 '17 at 10:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Which DBMS are you using? Oracle or SQL Server? And Have you tried something?
    – JSapkota
    Jan 22 '17 at 6:06










  • SQL SERVER, i have no idea how to do.....
    – Ajit Kumar
    Jan 22 '17 at 6:33






  • 1




    Please have a look here stackoverflow.com/q/194852/1530987
    – bhageena
    Jan 22 '17 at 6:46










  • Please read How to Ask.
    – Zohar Peled
    Jan 22 '17 at 8:07


















  • Which DBMS are you using? Oracle or SQL Server? And Have you tried something?
    – JSapkota
    Jan 22 '17 at 6:06










  • SQL SERVER, i have no idea how to do.....
    – Ajit Kumar
    Jan 22 '17 at 6:33






  • 1




    Please have a look here stackoverflow.com/q/194852/1530987
    – bhageena
    Jan 22 '17 at 6:46










  • Please read How to Ask.
    – Zohar Peled
    Jan 22 '17 at 8:07
















Which DBMS are you using? Oracle or SQL Server? And Have you tried something?
– JSapkota
Jan 22 '17 at 6:06




Which DBMS are you using? Oracle or SQL Server? And Have you tried something?
– JSapkota
Jan 22 '17 at 6:06












SQL SERVER, i have no idea how to do.....
– Ajit Kumar
Jan 22 '17 at 6:33




SQL SERVER, i have no idea how to do.....
– Ajit Kumar
Jan 22 '17 at 6:33




1




1




Please have a look here stackoverflow.com/q/194852/1530987
– bhageena
Jan 22 '17 at 6:46




Please have a look here stackoverflow.com/q/194852/1530987
– bhageena
Jan 22 '17 at 6:46












Please read How to Ask.
– Zohar Peled
Jan 22 '17 at 8:07




Please read How to Ask.
– Zohar Peled
Jan 22 '17 at 8:07












2 Answers
2






active

oldest

votes

















up vote
8
down vote













Use STUFF and FOR XML:



Create and populate sample table (Please save us this step in your future questions)



DECLARE @T AS TABLE
(
Name varchar(10)
)

INSERT INTO @T VALUES
('John'),
('Vicky'),
('Sham'),
('Anjli'),
('Manish')


The query:



SELECT STUFF((
SELECT ',' + Name
FROM @T
FOR XML PATH('')
), 1, 1, '') As [output];


Results:



output
John,Vicky,Sham,Anjli,Manish





share|improve this answer






























    up vote
    2
    down vote













    Assuming That your column name is NAME And table name is MYTABLE you can use the Following query:



    DECLARE @strTemp VARCHAR(MAX)

    SET @strTemp = ''

    SELECT @strTemp = @strTemp + ISNULL(NAME,'') + ','
    FROM MYTABLE

    --Remove last comma
    SET @strTemp = SUBSTRING(@strTemp ,1,LEN(@strTemp ) -1)

    --Get Result
    SELECT @strTemp


    You can filter null records using the following



    SELECT @strTemp  = @strTemp + NAME + ','
    FROM MYTABLE
    WHERE NAME IS NOT NULL





    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      8
      down vote













      Use STUFF and FOR XML:



      Create and populate sample table (Please save us this step in your future questions)



      DECLARE @T AS TABLE
      (
      Name varchar(10)
      )

      INSERT INTO @T VALUES
      ('John'),
      ('Vicky'),
      ('Sham'),
      ('Anjli'),
      ('Manish')


      The query:



      SELECT STUFF((
      SELECT ',' + Name
      FROM @T
      FOR XML PATH('')
      ), 1, 1, '') As [output];


      Results:



      output
      John,Vicky,Sham,Anjli,Manish





      share|improve this answer



























        up vote
        8
        down vote













        Use STUFF and FOR XML:



        Create and populate sample table (Please save us this step in your future questions)



        DECLARE @T AS TABLE
        (
        Name varchar(10)
        )

        INSERT INTO @T VALUES
        ('John'),
        ('Vicky'),
        ('Sham'),
        ('Anjli'),
        ('Manish')


        The query:



        SELECT STUFF((
        SELECT ',' + Name
        FROM @T
        FOR XML PATH('')
        ), 1, 1, '') As [output];


        Results:



        output
        John,Vicky,Sham,Anjli,Manish





        share|improve this answer

























          up vote
          8
          down vote










          up vote
          8
          down vote









          Use STUFF and FOR XML:



          Create and populate sample table (Please save us this step in your future questions)



          DECLARE @T AS TABLE
          (
          Name varchar(10)
          )

          INSERT INTO @T VALUES
          ('John'),
          ('Vicky'),
          ('Sham'),
          ('Anjli'),
          ('Manish')


          The query:



          SELECT STUFF((
          SELECT ',' + Name
          FROM @T
          FOR XML PATH('')
          ), 1, 1, '') As [output];


          Results:



          output
          John,Vicky,Sham,Anjli,Manish





          share|improve this answer














          Use STUFF and FOR XML:



          Create and populate sample table (Please save us this step in your future questions)



          DECLARE @T AS TABLE
          (
          Name varchar(10)
          )

          INSERT INTO @T VALUES
          ('John'),
          ('Vicky'),
          ('Sham'),
          ('Anjli'),
          ('Manish')


          The query:



          SELECT STUFF((
          SELECT ',' + Name
          FROM @T
          FOR XML PATH('')
          ), 1, 1, '') As [output];


          Results:



          output
          John,Vicky,Sham,Anjli,Manish






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 22 '17 at 8:03

























          answered Jan 22 '17 at 7:55









          Zohar Peled

          51.7k73172




          51.7k73172
























              up vote
              2
              down vote













              Assuming That your column name is NAME And table name is MYTABLE you can use the Following query:



              DECLARE @strTemp VARCHAR(MAX)

              SET @strTemp = ''

              SELECT @strTemp = @strTemp + ISNULL(NAME,'') + ','
              FROM MYTABLE

              --Remove last comma
              SET @strTemp = SUBSTRING(@strTemp ,1,LEN(@strTemp ) -1)

              --Get Result
              SELECT @strTemp


              You can filter null records using the following



              SELECT @strTemp  = @strTemp + NAME + ','
              FROM MYTABLE
              WHERE NAME IS NOT NULL





              share|improve this answer



























                up vote
                2
                down vote













                Assuming That your column name is NAME And table name is MYTABLE you can use the Following query:



                DECLARE @strTemp VARCHAR(MAX)

                SET @strTemp = ''

                SELECT @strTemp = @strTemp + ISNULL(NAME,'') + ','
                FROM MYTABLE

                --Remove last comma
                SET @strTemp = SUBSTRING(@strTemp ,1,LEN(@strTemp ) -1)

                --Get Result
                SELECT @strTemp


                You can filter null records using the following



                SELECT @strTemp  = @strTemp + NAME + ','
                FROM MYTABLE
                WHERE NAME IS NOT NULL





                share|improve this answer

























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Assuming That your column name is NAME And table name is MYTABLE you can use the Following query:



                  DECLARE @strTemp VARCHAR(MAX)

                  SET @strTemp = ''

                  SELECT @strTemp = @strTemp + ISNULL(NAME,'') + ','
                  FROM MYTABLE

                  --Remove last comma
                  SET @strTemp = SUBSTRING(@strTemp ,1,LEN(@strTemp ) -1)

                  --Get Result
                  SELECT @strTemp


                  You can filter null records using the following



                  SELECT @strTemp  = @strTemp + NAME + ','
                  FROM MYTABLE
                  WHERE NAME IS NOT NULL





                  share|improve this answer














                  Assuming That your column name is NAME And table name is MYTABLE you can use the Following query:



                  DECLARE @strTemp VARCHAR(MAX)

                  SET @strTemp = ''

                  SELECT @strTemp = @strTemp + ISNULL(NAME,'') + ','
                  FROM MYTABLE

                  --Remove last comma
                  SET @strTemp = SUBSTRING(@strTemp ,1,LEN(@strTemp ) -1)

                  --Get Result
                  SELECT @strTemp


                  You can filter null records using the following



                  SELECT @strTemp  = @strTemp + NAME + ','
                  FROM MYTABLE
                  WHERE NAME IS NOT NULL






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 22 '17 at 9:07

























                  answered Jan 22 '17 at 8:54









                  Hadi

                  16.3k62570




                  16.3k62570















                      Popular posts from this blog

                      鏡平學校

                      ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                      Why https connections are so slow when debugging (stepping over) in Java?