Sunday, March 11, 2012

Create Procedure #Test in another SP?

Hi,

I was wondering if it's possible to create a local stored procedure within another stored procedure? Something like the following:

CREATE PROCEDURE [sti_edocsecure].[spPagingDynamicWrapper]

@.Page int,
@.Size int,
@.ItemStatus int,
@.UserId int,
@.TableName varchar(255),
@.Select varchar(8000),
@.Criteria varchar(8000)

AS

BEGIN TRANSACTION

SET NOCOUNT ON

CREATE PROCEDURE #Test
@.Page int,
@.Size int,
@.ItemStatus int,
@.UserId int,
@.TableName varchar(255),
@.Select varchar(8000),
@.Criteria varchar(8000)

AS

BEGIN TRANSACTION

SET NOCOUNT ON

RETURN 0

COMMIT TRANSACTION
Return 0

COMMIT TRANSACTION
GO

According to MSDN you can do this but I can't find any samples. The above SP gives me an error saying:

Error 156: Incorrect syntax near the keyword 'PROCEDURE'.

So, I don't know if I'm doing something wrong or if this is even possible.

Thanks for any insight anyone can provide,

CraigNot quite sure why U'd want 2 but

declare @.sql nvarchar(500)
select @.sql = 'Create Procedure AAA As SELECT 1 as one'

exec sp_executesql @.sql

Handy little sp this one [sp_executesql]

GW

No comments:

Post a Comment