gpt4 book ai didi

sql - SQL Server 语法错误

转载 作者:行者123 更新时间:2023-12-02 05:27:21 25 4
gpt4 key购买 nike

这可能是一个愚蠢的语法错误,但我一直在阅读我的程序,但我无法弄清楚我的错误在哪里。

Msg 156, Level 15, State 1, Line 41
Incorrect syntax near the keyword 'FOR'.

这是我的代码:

alter procedure LockReservation as
DECLARE @edition_id tinyint, @stockid tinyint;
DECLARE @creservation CURSOR FOR select edition_id from reservation where (date_fin - GETUTCDATE()) <= 12;
open creservation;
while @@fetch_status = 0
BEGIN
fetch creservation into @edition_id;
DECLARE @cstock CURSOR
FOR select id from stock where edition_id = @edition_id;
open cstock;
while @@fetch_status = 0
BEGIN
fetch cstock into @stockid;
select stock_id from location where location.stock_id = @stockid and archivage = 0
if @@rowcount = 0
BEGIN
insert into stocks_reserves(id, date_ajout, usure, suppression, edition_id)
Select id, date_ajout, usure, suppression, edition_id
from stock
where stock.id = @stockid
END
END
CLOSE cstock
DEALLOCATE cstock
END
CLOSE creservation
DEALLOCATE creservation

有人可以帮帮我吗?

最佳答案

不要在光标名称中使用 @ 符号。

关于sql - SQL Server 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5491181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com