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".
I see two issues here:
@myDate
and@ServerName
, which you have not declared yet. Do so by adding the names and the types between the procedure name and AS.When calling sp_1 to sp_4, there is no need to specify the data type of the parameters again (that's been taken care of by the declaration, see point 1).
You are executing stored procedures the wrong way
is completely wrong syntax.
When you have to execute a stored procedure with parameters, first declare parameter and pass it..
This is the right approach..
Try this one -