I have stored procedures with same parameters (server name and date). I want to write a stored procedure and Exec them in that SP (called it SP_All).
CREATE PROCEDURE [dbo].[SP_All]
AS
BEGIN
exec sp_1 @myDate datetime, @ServerName sysname
exec sp_2 @myDate datetime, @ServerName sysname
exec sp_3 @myDate datetime, @ServerName sysname
exec sp_4 @myDate datetime, @ServerName sysname
END
Go
error: Must declare the scalar variable "@myDate".
Try this one -
CREATE PROCEDURE [dbo].[SP_All]
@myDate DATETIME
, @ServerName SYSNAME
AS BEGIN
EXEC dbo.sp_1 @myDate, @ServerName
EXEC dbo.sp_2 @myDate, @ServerName
EXEC dbo.sp_3 @myDate, @ServerName
EXEC dbo.sp_4 @myDate, @ServerName
END
You are executing stored procedures the wrong way
exec sp_1 @myDate datetime, @ServerName sysname
is completely wrong syntax.
When you have to execute a stored procedure with parameters, first declare parameter and pass it..
declare @myDate datetime
declare @ServerName sysname
exec sp_1 @myDate, @ServerName
This is the right approach..