小编Adi*_*zky的帖子

执行存储过程时"必须声明标量变量"错误

我试图制作一个插入价格的程序:

create procedure prInsertPrice
@NuggetID varchar(5),
@Unit_Price money,
@Start_Date datetime,
@End_Date datetime
as
begin
DECLARE @date AS DATETIME
SET @date = GETDATE()
    if
        (
        (@NuggetID like 'N[0-9][0-9]')
        and
        (@Unit_Price is not null)
        and
        (@Start_Date is not null)
        )
    begin
        print 'Insert Success'
        insert NuggetPrice (NuggetId, Unit_Price, Start_Date, End_Date)
        values (@NuggetID, @Unit_Price, @Start_Date, @End_Date)
    end
    else
    begin
        print 'Failed to insert'
    end
end
Run Code Online (Sandbox Code Playgroud)

当我执行程序时没关系,但是当我运行这样的程序时:

EXEC prInsertPrice 'N01', 20000, @date, null
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

必须声明标量变量@date.

为什么这样,我该如何纠正这个问题?

sql t-sql sql-server stored-procedures sql-server-2012

1
推荐指数
1
解决办法
1万
查看次数