存储过程中的两个错误:接近预期变量的语法不正确,必须声明标量变量

时间:2021-02-26 19:13:07

I created a stored procedure in SSMS 17.6

我在SSMS 17.6中创建了一个存储过程

USE Stock
GO

CREATE PROCEDURE Add_Item
    @Name VARCHAR(20),
    @Section INT,
    @Size INT,
    @Grade INT,
    @Weight INT,
AS   // i get this error (incorrect syntax near as expecting variable)
    INSERT INTO [Item] ([Name_Item], [ID_SectionType], [SectionSize_Item],
                        [ID_Grade], [Weight])
    VALUES (@Name, @Section, @Size,
            @Grade, @Weight)
GO

I get this error

我收到这个错误

Must declare the scalar variable

必须声明标量变量

How can I solve this problem?

我怎么解决这个问题?

Thanks in advance

提前致谢

1 个解决方案

#1


1  

-- you have extra comma after first variable before the AS, this fixes it 

Create Proc Add_Item

@Name varchar (20),
@Section int,
@Size int,
@Grade int,
@Weight int
AS --//i get this error (incorrect syntax near as expecting variable)
INSERT INTO [Item]
([Name_Item]
,[ID_SectionType]
,[SectionSize_Item]
,[ID_Grade]
,[Wight])
VALUES
(@Name
,@Section
,@Size
,@Grade
,@Weight)
GO

#1


1  

-- you have extra comma after first variable before the AS, this fixes it 

Create Proc Add_Item

@Name varchar (20),
@Section int,
@Size int,
@Grade int,
@Weight int
AS --//i get this error (incorrect syntax near as expecting variable)
INSERT INTO [Item]
([Name_Item]
,[ID_SectionType]
,[SectionSize_Item]
,[ID_Grade]
,[Wight])
VALUES
(@Name
,@Section
,@Size
,@Grade
,@Weight)
GO