Sybase ASE 15 Aggregate Function for strings

蹲街弑〆低调 提交于 2019-12-02 05:41:56

问题


I'am findind a way to aggregate strings from differents rows into a single row in sybase ASE 15. Like this:

id | Name                    Result: id | Names
-- - ----                            -- - -----
1  | Matt                            1  | Matt, Rocks
1  | Rocks                           2  | Stylus
2  | Stylus

Something like FOR XML PATH in T-SQL.

Thanks!


回答1:


Sybase ASE does not have any string aggregate functions like list() or group_concat(); and while there is some support for FOR XML, it does not include support for the PATH option/feature.

Assuming you could have an unknown/variable number of rows to append, your only (ASE 15) T-SQL option would be a cursor-based solution.

If you find yourself working with ASE 16 you could write a user-defined function (UDF) to accomplish the task, eg: emulate group_concat() in ASE 16




回答2:


You could try this:

select id,list(Names,',' order by id) from TableName a group by id 


来源:https://stackoverflow.com/questions/45091053/sybase-ase-15-aggregate-function-for-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!