SQL Server 2017之前的string

编程入门 行业动态 更新时间:2024-10-25 18:27:30
本文介绍了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

本文发布于:2023-10-17 07:03:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Server   SQL   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!