本文介绍了如何在存储过程中调用存储过程(带有2个参数)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的存储过程具有相同的参数(服务器名称和日期).我想编写一个存储过程,并在该SP(称为SP_All)中执行它们.
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
错误:必须声明标量变量"@myDate".
error: Must declare the scalar variable "@myDate".
推荐答案
我在这里看到两个问题:
I see two issues here:
- 您的过程显然带有两个参数,
@myDate
和@ServerName
,您尚未声明.为此,请在过程名称和AS之间添加名称和类型. -
在将sp_1调用到sp_4时,无需再次指定参数的数据类型(声明已处理了该数据类型,请参见第1点).
- Your procedure apparently takes two parameters,
@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).
CREATE PROCEDURE [dbo].[SP_All]
@myDate datetime,
@ServerName sysname
AS
BEGIN
exec sp_1 @myDate, @ServerName
exec sp_2 @myDate, @ServerName
exec sp_3 @myDate, @ServerName
exec sp_4 @myDate, @ServerName
END
这篇关于如何在存储过程中调用存储过程(带有2个参数)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!