Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2012
    Posts
    1

    Unanswered: Convert select to comma separated output

    Hello,

    I've got a problem with a query, maybe someone can help me...

    Two tables (for example with names and phonenumbers):

    id | name
    1 | john
    2 | anna

    id | nameid | number
    1 | 1 | 1234
    2 | 1 | 5678
    3 | 2 | 9876
    4 | 2 | 5432

    I need a select statement which gives me the following output:

    name | number
    john | 1234, 5678
    anna | 9876, 5432

    Anyone who can help me? Thanks!

    Regards,
    Alex

  2. #2
    Join Date
    Feb 2012
    Location
    Pune
    Posts
    11

    Convert select to comma separated output

    use below query

    lets say first table name is name1 and second is name2

    select x.name,convert(char,a.number) + ","+ convert(char,b.number)
    from name1 x, name2 a,name2 b
    where x.d = a.nameid
    and a.nameid =b.nameid
    and a.id < b.id

  3. #3
    Join Date
    Feb 2012
    Location
    India,Mumbai
    Posts
    34

    Convert select to comma separated output

    Hi ,

    how it going to work if employee has more than 2 rows ? there should be some generic answer which need to be work independent to number of rows . In Db2 , I know , we have LISTAGG function or recursive query option to achieve this . not sure about Sybase .

Posting Permissions

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