SQL Server 上的语法错误 [英] Syntax error on SQL Server
本文介绍了SQL Server 上的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个愚蠢的语法错误,但我只是继续阅读我的程序,但我不知道我的错误在哪里.
this could be a stupid syntax error but I just keep reading my procedure but i cannot figure out where are my errors.
消息 156,级别 15,状态 1,第 41 行
关键字附近的语法不正确'为'.
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
有人可以帮我吗?
推荐答案
不要在光标名称中使用 @ 符号.
Don't use the @ symbol in your cursor names.
这篇关于SQL Server 上的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文