I have tried to make a procedure to insert a price:
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
When I execute the procedure it's fine, but when I run the procedure like this:
EXEC prInsertPrice 'N01', 20000, @date, null
I get the error message:
Must declare the scalar variable @date.
Why is this and how can I correct the problem?