Efficient way to string split using CTE(使用 CTE 进行字符串拆分的有效方法)
问题描述
我有一张看起来像的桌子
I have a table that looks like
所需的输出应该是
我已通过以下查询完成此操作
I have done this by the below query
但从性能上来说,这是非常糟糕的.我正在寻找更有效的查询,但仅使用 CTE.
But performance wise it is very bad. I am looking for a more efficient query but using CTE only.
推荐答案
你似乎对使用 CTE 死心塌地,所以试试这个:
You seem dead set on using a CTE, so try this:
输出:
这里有一篇关于在 SQL Server 中拆分字符串的优秀文章:"Arrays andSQL Server 2005 及更高版本中的列表,当表值参数不剪切时"作者:Erland Sommarskog
here is an excellent article on splitting strings in SQL Server: "Arrays and Lists in SQL Server 2005 and Beyond, When Table Value Parameters Do Not Cut it" by Erland Sommarskog
EDIT 这是另一个版本(但您需要一个数字表)返回与上述相同的结果:
EDIT here's another version (but you need a numbers table) returns same results as above:
在此处查看数字表格:创建和填充数字表格的最佳方法是什么?
这篇关于使用 CTE 进行字符串拆分的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!