I am having difficulty establishing the correct syntax for calling a stored procedure within a stored procedure. I thought this syntax was correct:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[newProc](
@param1 varchar(50),
@param2 nvarchar(2000),
@param3 int,
@param4 int,
@param5 int,
@param6 int
)
AS
BEGIN
SET NOCOUNT ON;
EXEC [dbo].[externProc1] @param1, @param2;
GO
EXEC [dbo].[externProc2] @param3, @param4;
GO
EXEC [dbo].[insertProc3] @param5, @param6;
GO
END
GO
But when I try this, I keep getting
“Incorrect syntax near ‘;’ Must declare the scalar variable @param3.
Must declare the scalar variable @param5.”
What is the correct syntax for calling a stored procedure with parameters from within another stored procedure?
The
GOkeyword in T-SQL states that a block of t-sql statements ends and executes that block. This means that a variable defined in one block is not longer “in scope” for a statement occurring after that block has been ended/executed withGO.GO is not actually a transact sql statement:
http://msdn.microsoft.com/en-us/library/ms188037(v=sql.105).aspx