我用光标得到了这个过程
CREATE PROCEDURE usp_Inventario
AS
DECLARE @Id int, @Nombre varchar(255), @precio decimal, @st int, @inv int
SET @inv = 0
DECLARE cproducto CURSOR FOR
SELECT P.ProductID, P.ProductName, P.UnitPrice, P.UnitsInStock
FROM Products P
和
OPEN cproducto
FETCH cproducto INTO @id, @Nombre, @precio, @st
WHILE (@@FETCH_STATUS = 0)
BEGIN
PRINT Str(@id) + space(5) + str(@nombre) + space(5) + Str(@precio) + space(5) + Str(@st)
SET @inv += @st
FETCH cproducto INTO @id, @Nombre, @precio, @st
END
CLOSE cproducto
DEALLOCATE cproducto
PRINT 'Inventario de Productos:' + Str(@inv)
我收到此错误
必须声明标量变量“ @id”
多次,有人可以告诉我我在做什么错吗?
答案 0 :(得分:0)
至少,您需要begin
/ end
:
CREATE PROCEDURE usp_Inventario
AS
BEGIN
DECLARE @Id int, @Nombre varchar(255), @precio decimal, @st int, @inv int;
SET @inv=0;
DECLARE cproducto CURSOR FOR
SELECT P.ProductID, P.ProductName, P.UnitPrice, P.UnitsInStock
FROM Products P;
. . .
END;