cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert a column into comma-separated string in HANA DB

0 Kudos

In SQL server we could do something like this. Please see the source here.

declare @results varchar(500)
select @results = coalesce(@results + ',', '') +  convert(varchar(12),col)
from t
order by col
select @results as results
| RESULTS |
-----------
| 1,3,5,9 |

How do I do it in HANA DB?

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

A simple look into the online documentation or searching here in the forum would produce the STRING_AGG function as result. This function does exactly what you require, when you use a comma as separator sign.

Regards,
Florian

0 Kudos

Yeah, I had found it too. Searching in the literature was not very obvious or easy though.

I am sorry, I should have updated my answer.

Thanks

0 Kudos

Hi Florian,

Is there an easy to do the reverse as well? Converting the comma (delimited separated) values into a column? Or do I have to write my own function for that?

Thanks

lbreddemann
Active Contributor

Yes, for that you need a custom function. Fortunately, you're not the first to ask this question and you can put your google-foo to find examples for this in the archive pages of SCN.

Answers (0)