on 10-15-2014 6:52 PM
Suppose I have a stored procedure sp1 which call another procedure sp2 like:
create proc sp1
as
begin
CREATE TABLE #table1 (......)
Exec sp2
end
then I want to use #table1 in sp2, like
create proc sp2
as
begin
....
delete from #table1
INSERT INTO #table1
......
end
How to pass #table1 to sp2? Anywhere to do this?
The trick to setting this up is to create the #temp1 table before creating sp2 to avoid any "object not found" resolution error while the query tree is being created. The drop the table.
When sp2 is called by sp1, it will automatically re-resolve it's #temp1 entry to the #temp1 created in sp1.
CREATE TABLE #table1 (......)
go
create proc sp2
as
begin
....
delete from #table1
INSERT INTO #table1
......
end
go
drop table #table1
go
create proc sp1
as
begin
CREATE TABLE #table1 (......)
Exec sp2
end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks, got it. Bret. One more question. If sp2 call another sp3, if this #table1 available for sp3 if I doing thing like:
sp1.
CREATE TABLE #table1 (......)
go
create proc sp3
as
begin
....
delete from #table1
INSERT INTO #table1
......
end
create proc sp2
as
begin
....
delete from #table1
INSERT INTO #table1
exec sp3
......
end
go
drop table #table1
go
create proc sp1
as
begin
CREATE TABLE #table1 (......)
Exec sp2
end
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.