TSQL使EXECUTE语句同步

TSQL使EXECUTE语句同步

本文介绍了TSQL使EXECUTE语句同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个TSQL EXEC语句

I have two TSQL EXEC statements

EXECUTE (N'MyDynamicallyGeneratedStoredProcedure') -- return 0 on success
SELECT @errCode = @@ERROR ;

IF (@errCode = 0)
BEGIN
  EXEC 'A Sql Statement using ##temptable created from first', @returnValue
END

如何使两个EXEC同步?;现在,第二个EXEC不会等待第一个EXECUTE完成.我尝试发出WaitFor Delay,它等待,但是第二个EXEC语句永不恢复.

How do I make the two EXEC's synchronous? ; Right now the second EXEC does not wait for the first EXECUTE to complete. I tried issuing a WaitFor Delay, It waits but the second EXEC statement is never returing back.

谢谢.

更新,这里是更多信息:

  1. 首先执行将创建一个全局临时表,并从一个复杂的SELECT查询中填充它.
  2. 第二个EXEC是CLR存储过程,它基于最近创建并填充的Global Temp表中的变量来生成动态SP.

现在,第二个EXEC抱怨找不到Global Temp表.

Now the second EXEC, complains that the Global Temp table is not found.

更新2,发现了问题(还有我!)

GBN(及其他)在答案上为空白.EXEC是同步的.问题?我对问题本身的理解..我已经提到过

GBN (and others) was point blank on the answer. EXEC IS synchronous. The problem? My understanding of the problem itself.. I had mentioned

  1. 执行(N'MyDynamicallyGeneratedStoredProcedure')-成功返回0

应该是:

1(a)执行(N'CreateMyDynamicStoredProcedure')-成功返回0

1(a) EXECUTE (N'CreateMyDynamicStoredProcedure') -- return 0 on success

1(b)执行(N'MyDynamicStoredProcedure')-成功返回0

我错过了1(b)实际上在其他地方并且在步骤(2)之后执行的情况.

I missed that 1(b) was actually executed somewhere else and after step (2) .

(我应该去死!!)

推荐答案

EXECUTE是同步的.第二个运行在第一个之后.总是.

EXECUTE is sychronous. The 2nd one runs after the 1st one. Always.

您是否有多个运行相同代码的连接?您正在使用对所有连接可见的全局临时表,因此它看起来像异步执行...

Do you have multiple connections running the same code? You are using a global temp table that will be visible to all connections so it may look like asyncc execution...

这篇关于TSQL使EXECUTE语句同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:44