3

我发现执行 SP1 时,SP2 不会从 SP1 内执行。

SP1的结构如下:

ALTER PROCEDURE SP1 AS BEGIN

Declare c1 cursor....

open c1 fetch next from c1 ...

while @@fetch_status = 0 Begin

...

Fetch Next from c1 end

close c1

deallocate c1

exec sp2

end

如果在 SQL Server 2005 管理工作室的“输出窗口”中打印,我看不到任何 PRINT 语句输出,因为“输出窗口”为空。

4

3 回答 3

3

What happens if you run the Stored Procedure code as a single query? If you put a PRINT statement before and after the exec, do you see both outputs?

  • If you do, then the stored procedure must have been executed. Probably it's not doing what you would like.
  • If you don't see any print output, then there's something wrong in the cycle
  • If you don't see the second output but you see the first, there's something wrong in the second Stored Procedure.
于 2008-10-04T14:46:28.570 回答
0

我不确定它是否对您有帮助,但根据我的经验,最常见的原因是:

  1. sp2获取一些使其null值的参数 - 即您从字符串构建它的名称,其中之一是null.
  2. sp2里面有一些条件,没有一个是真的,所以sp2根本不执行任何代码——即参数之一是 type varchar,你传递 value VALUE,在里面检查它,但传递给的真实值sp2V(因为没有 varchar 长度定义)。
  3. sp2从参数之一构建查询,null整个查询也变成null了。

如果您在调用PRINT 之前之后sp2放置,您会看到任何输出吗?

于 2008-10-20T19:48:26.380 回答
0

您可以使用@@error 来查看执行上一条语句时是否有错误。

于 2009-01-22T14:52:01.500 回答