Hier ist das Skript zu erstellen:Fehler, wenn ein SQL-Skript
create procedure sp_DescuentoAlquiler
as
declare @IDAlquiler int, @NumeroPelicula int, @MontoTotal float
declare cursorAlquiler cursor for
select a.ID, count(d.ID) as @NumeroPelicula
from Alquiler a inner join DetalleAlquiler d on a.ID = d.IDAlquiler
group by a.ID
open cursorAlquiler
fetch next from cursorAlquiler into @IDAlquiler, @NumeroPelicula
while @@FETCH_STATUS = 0
begin
if(@NumeroPelicula >= 3)
begin
select @MontoTotal = SUM(d.PrecioAlquiler)
from DetalleAlquiler d where d.IDAlquiler = @IDAlquiler
update Alquiler set MontoTotal = @MontoTotal * 0.3
where ID = @IDAlquiler
end
fetch next from cursorAlquiler into @IDAlquiler, @NumeroPelicula
end
close cursorAlquiler
deallocate cursorAlquiler
Ich erhalte einen Fehler in Zeile 6 nach Zählung (d.ID), auf @NumeroPelicula:
Msg 102, Ebene 15, Status 1, Prozedur sp_DescuentoAlquiler, Zeile 6 Falsche Syntax in der Nähe von '@NumeroPelicula'.
Irgendwelche Vorschläge?
Dies ist natürlich etwas, das nicht in einem Cursor erfolgen soll. – HLGEM