有人可以帮助我将其重构为更友好的表现吗?我正在使用的结果集中有419行。
declare @docid uniqueidentifier
declare @publish_xml nvarchar(max) = null
declare @pub_text1 nvarchar(max) = null
declare @pub_text2 nvarchar(max) = 'Physical Mail'
declare @pub_text3 nvarchar(max) = null
declare cur CURSOR LOCAL for
select d.document_id, d.published_xml, d.published_text1, d.published_text2, d.published_text3
from tblCMS_Document d
where d.template_id = '357760AD-1D33-4162-A813-20F56901C18D'
open cur
fetch next from cur into @docid, @publish_xml, @pub_text1, @pub_text2, @pub_text3
while @@FETCH_STATUS = 0 BEGIN
exec [usp_CMS_Document_Publish] @docid, @publish_xml, @pub_text1, 'Physical Mail', @pub_text3
END
CLOSE cur
DEALLOCATE cur
答案 0 :(得分:2)
这不能解答您的问题,但这可能是您的光标永远运行的原因。你在while循环中缺少一个FETCH NEXT:
open cur
fetch next from cur into @docid, @publish_xml, @pub_text1, @pub_text2, @pub_text3
while @@FETCH_STATUS = 0 BEGIN
exec [usp_CMS_Document_Publish] @docid, @publish_xml, @pub_text1, 'Physical Mail', @pub_text3
fetch next from cur into @docid, @publish_xml, @pub_text1, @pub_text2, @pub_text3
END
答案 1 :(得分:0)
我会将游标查询移动到usp_CMS_Document_Publish中,并在基于集合的方法上执行此发布操作。是否无法编辑usp_CMS_Document_Publish?