I got this procedure with a cursor
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
and
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)
I get this error
Must declare the scalar variable "@id"
multiple times, could someone please tell me what I am doing wrong?