Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    8

    Question Unanswered: How to generate concatenated string from all rows in sybase

    Hi All,
    I am looking for a best solution in order to generate a comma delimited string from all the rows of a table without using any loop or cursor etc.
    Eg:

    employee table has below values:
    name
    -----
    abc
    xyz

    Desired output would be : abc,zyz

    I know this can be done in just one single sql using variables but not sure how to do that. Any suggestion geeks ?

  2. #2
    Join Date
    Jun 2010
    Posts
    51
    Try this:
    Code:
    declare @concate varchar(500)
    
    update employee
    set @concate = @concate + "," + name
    
    select @concate = substring(@concate,2,len(@concate))
    
    select @concate
    
    select * from employee
    Separator here is ",". You can change that to what ever you want.
    Please always reply to the post if it was helpful. Others may find it helpful.

  3. #3
    Join Date
    Sep 2010
    Posts
    8

    Thumbs up How to generate concatenated string from all rows in sybase

    Superb! Thanks Meet.
    this is the kind of solution I was looking for. I will try to use this idea ( just need to extend it for some scenarios).
    Great and thanks again.

    rgds.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •