问题描述
在Firebird中,有一个名为会将多个结果转换成逗号分隔的字符串。
In Firebird, there's an aggregate called List()
that turns multiple results into a comma-separated string.
此功能在SQL Server中似乎不存在。是否有任何等效方法不涉及使用 for xml
进行大而长,丑陋,慢的变通方法或将您自己构建为CLR UDF? (是的,我知道那些方法。正在寻找我可能不知道的东西。)
This function does not appear to exist in SQL Server. Is there any equivalent to it that doesn't involve a big, long, ugly, slow workaround using for xml
or building your own as a CLR UDF? (Yes, I know about those methods. Looking for something I might not be aware of.)
推荐答案
否,这些是您将不得不使用的解决方法。自2006年以来,我们一直要求提供 GROUP_CONCAT
等效项:
No, those are the workarounds you will have to use. We have been asking for a GROUP_CONCAT
equivalent since 2006:
...但是该项目仅获得13票赞成(和1票反对) )。因此,我不能完全怪罪微软专注于产品的其他增强功能以提高销售和客户满意度。没有很多人抱怨(至少不是直接抱怨), GROUP_CONCAT
并不是营销人员可以在幻灯片平台或商业广告上表现出性感的东西-开发人员的生产力并不完全是销售许可证的产品。 (另一方面,我想认识14个以上设法获得愚蠢的东西的人,例如 EOMONTH
和 IIF
已实施。)
...but the item has only received 13 up-votes (and one down-vote). So I don't exactly blame Microsoft for focusing on other enhancements to the product in order to drive sales and customer satisfaction. Not a lot of people have complained (at least not directly), and GROUP_CONCAT
is not something the marketing people can make look sexy on a slide deck or in a commercial - developer productivity is not exactly what sells licenses. (On the other hand, I'd like to meet the 14+ people who managed to get silly things like EOMONTH
and IIF
implemented.)
因此,如果您认为此功能很重要,请投票,更重要的是,评论一下这将如何提高您的生产率/行:
So, if you think this functionality is important to have, then please vote and, more importantly, comment on how this will improve your productivity / bottom line:
FWIW,XML版本很难看,但是掌握起来并不难。我已经在SO上的数十个答案中使用了它,甚至不必再查找它。我也不认为它的运行速度非常慢。您为什么认为Microsoft本机放入的内容会更快?基本上必须做同样的事情。
FWIW, the XML version is ugly, but it is not hard to master. I've used it in dozens of answers here on SO and I don't even have to go look it up anymore. I also don't find it to be terribly slow. Why do you think something Microsoft puts in natively will be any faster? It will have to do essentially the same thing.
这篇关于有没有什么好方法可以在SQL Server中建立逗号分隔的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!