本文介绍了SQL Server 2017之前的string_agg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我使此查询适用于sql server2014.这适用于Postgresql,也可能适用于sql server2017.在Oracle上,它是listagg而不是string_agg.
Can anyone help me make this query work for sql server 2014. This is working on Postgresql and probably on sql server 2017. On Oracle it is listagg instead of string_agg.
这是sql:
select string_agg(t.id,',') AS id from Tabel t我在网站上检查了应使用的xml选项,但我听不懂.
I checked on the site some xml option should be used but I could not understand it.
推荐答案在SQL Server 2017之前的版本中,您可以执行以下操作:
In SQL Server pre-2017, you can do:
select stuff( (select ',' + cast(t.id as varchar(max)) from tabel t for xml path ('') ), 1, 1, '' );stuff()的唯一目的是删除初始逗号.该工作由for xml path完成.
The only purpose of stuff() is to remove the initial comma. The work is being done by for xml path.
更多推荐
SQL Server 2017之前的string
发布评论