Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Unanswered: Row aggregation like MySQL group_concat

    Hi,

    I'm pretty new to Sybase, but I would like to know how I can concat columns together. For example, I have the following result set:

    Ref | Desc
    1 GBP
    1 JPY
    1 USD
    2 GBP
    3 JPY
    3 EUR
    4 GBP

    But would like to get the following resultset

    Ref | Desc
    1 GBP, JPY, USD
    2 GBP
    3 JPY, EUR
    4 GBP


    Now if I was using MySql I would use the Group_Concat function and I believe Sybase has something similiar called list, but unfortunately this function is not available to me. I am using Sybase 15.0.3 ASE

    Any help would be most greatful.

    Thanks

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    List is in the Sybase SQL Anywhere database product not in ASE

  3. #3
    Join Date
    Jan 2010
    Posts
    2
    Thanks pdreyer for the reply, but I knew this, hence saying it was not available to me. What I'm after is what people do to get around this. Is there some sort of SQL to do this easily? My SQL isn't that great so just interest in some tips going forward with some I feel would be quite a common thing to do.

    Thanks

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    A bug in very old versions allowed you to do something like this to concatenate values

    declare @s varchar(100)
    select @s = ''
    select @s = @s + name
    from #emp

    The below might still work
    declare @a varchar (100)
    update #emp set @a = @a + name
    select @a

    But I suggest you write code to loop

Posting Permissions

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