Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 nested stored procedures

Author  Topic 

ben_53
Yak Posting Veteran

67 Posts

Posted - 2011-08-31 : 15:21:51
Hi guys,

I have 10 stored procedures and I need to run these 10 stored procedures in one SP.

I am trying to nest them up but unable. The script Im using is :


IF NOT EXISTS(SELECT id FROM sysobjects WHERE id =
object_id('dbo.Main_sp'))

EXECUTE ('CREATE procedure dbo.Main_sp AS SELECT 0 AS temp')

GO


ALTER PROCEDURE dbo.Main_sp
AS

BEGIN
/*** EXECUTE SP1 ***/

IF NOT EXISTS(SELECT id FROM sysobjects WHERE id =
object_id('dbo.sp1'))

EXECUTE ('CREATE procedure dbo.sp1 AS SELECT 0 AS temp')



ALTER PROCEDURE dbo.sp1
AS
......
....
END

/*** same for 2 -10 ***/

END




Nested stored procedures wont run. please help me correct the code. Thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-31 : 15:59:43
Your code makes no sense. It's dynamically creating stored procedures, which doesn't sound like what you want. I am thoroughly confused what you actually do want, but here's a shot:

create proc sp3 as select 1
go
create proc sp2 as exec sp3
go
create proc sp1 as exec sp2
go

exec sp1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-01 : 00:02:51
I really cant understand why someone would want to do this? Can you explain what you're trying to achieve by above dynamic sp code?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -