问题描述
我有一个循环,它检查表 tmp13
中 descript
列的所有名称和日期,并将它们作为单独的行存储在其他表中 (tmp14).问题是while循环执行了很长时间.我不知道如何让它运行得更快.
I have a loop that checks all the names and dates from descript
column from table tmp13
and stores them as individual rows in other table (tmp14
). The problem is that the while loop is executing for a long time. I don't know how to make it run faster.
这是我的代码,检查名称和日期的 descript
列.Descript
是一个文本列,可以有多个名称和日期.我想将这些名称和日期存储在单独的行中.
Here is my code checking the descript
columns for names and date. Descript
is a text column and can have multiple names and dates. I want to store those names and dates in separate rows.
---样本表
);
推荐答案
While 循环会很慢,因为当您使用过程逻辑在声明式编程语言中进行开发时会发生这种情况.为此,您可以使用 patternSplitCM.您的示例数据存在问题,但这应该可以满足您的需求.
While loops will be slow because that's what happens when you use procedural logic to develop in a declarative programming language. For this you can use patternSplitCM. There are issues with your sample data but this should get you what you need.
结果:
最后,为了获得最佳性能,您希望 p_Num、REQUESTED、DATE1、BY1 列上的索引支持 GROUP BY 子句.索引看起来像:
Lastly, for optimal performance you want an index on the columns p_Num,REQUESTED,DATE1,BY1 to support the GROUP BY clause. The index would look something like:
另请注意,使用并行执行计划可能会运行得更快.为此,您可以使用 TRACEFLAG 8649 或 Adam Machanic 的 make_parallel().
Also note that this will likely run faster with a parallel execution plan. For that you can use TRACEFLAG 8649 or Adam Machanic's make_parallel().
这篇关于在 SQL Server 中,while 循环需要很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!