先看代码
Create Procedure up_test1 as
Select '1111' --这里没有问题
go
Create Procedure up_test2 AS
create table #tt (a Varchar(4))
insert into #tt Exec up_test1
go
Create Procedure up_test3 as
Create Table #ttt (b varchar(4))
Insert Into #ttt Exec up_test2
go
exec up_test3 --这个执行就不能通过。
Select '1111' --这里没有问题
go
Create Procedure up_test2 AS
create table #tt (a Varchar(4))
insert into #tt Exec up_test1
go
Create Procedure up_test3 as
Create Table #ttt (b varchar(4))
Insert Into #ttt Exec up_test2
go
exec up_test3 --这个执行就不能通过。
经过向BAIDU GOOGLE 等大仙求救都无任何音讯后自己摸索
简单更改了一下存储过程就能执行通过
--
-- Create Procedure up_test1 as
-- Select '1111' --这里没有问题
--go
Alter Procedure up_test2 AS
create table #tt (a Varchar(4))
Declare @strsql nvarchar(2000)
set @strsql='insert into #tt'
Exec up_test1
go
--Create Procedure up_test3 as
-- Create Table #ttt (b varchar(4))
-- Insert Into #ttt Exec up_test2
--go
exec up_test3 --这个执行就能通过。
-- Create Procedure up_test1 as
-- Select '1111' --这里没有问题
--go
Alter Procedure up_test2 AS
create table #tt (a Varchar(4))
Declare @strsql nvarchar(2000)
set @strsql='insert into #tt'
Exec up_test1
go
--Create Procedure up_test3 as
-- Create Table #ttt (b varchar(4))
-- Insert Into #ttt Exec up_test2
--go
exec up_test3 --这个执行就能通过。
……
有时候稍微转个小弯就能搞定问题
本文探讨了在SQL Server中创建并调用多个嵌套存储过程的问题。通过对比两种不同的实现方式,指出了直接在存储过程中使用EXEC调用其他存储过程可能导致的问题,并提供了一种可行的解决方案。

1798

被折叠的 条评论
为什么被折叠?



