If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Row aggregation like MySQL group_concat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-10, 09:27
Nick309tt Nick309tt is offline
Registered User
 
Join Date: Jan 2010
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 01-12-10, 01:13
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
List is in the Sybase SQL Anywhere database product not in ASE
Reply With Quote
  #3 (permalink)  
Old 01-12-10, 12:45
Nick309tt Nick309tt is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 01-13-10, 05:13
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On