猿问

关键字 'for' 附近有语法错误?

declare @PtnLimitTime datetime
declare @cursor CURSOR for
Select PtnLimitTime from tblPlanTableName
open @cursor
fetch next from @cursor into @PtnLimitTime
while(@@fetch_status=0)begin
print @PtnLimitTime
fetch next from @cursor into @PtnLimitTime
end
close @cursor
deallocate @cursor

错误提示:
消息 156,级别 15,状态 1,第 3 行
关键字 'for' 附近有语法错误。
错误提示:
消息 156,级别 15,状态 1,第 2行
关键字 'for' 附近有语法错误。

弄错提示了。

慕姐4208626
浏览 180回答 2
2回答

肥皂起泡泡

把cursor名前面的@去掉,如下:declare cursor_1 CURSOR forSelect PtnLimitTime from tblPlanTableNameopen cursor_1fetch next from cursor_1 into @PtnLimitTimewhile(@@fetch_status=0)beginprint @PtnLimitTimefetch next from cursor_1 into @PtnLimitTimeendclose cursor_1deallocate cursor_1

智慧大石

declare @PtnLimitTime datetimedeclare cursor1 CURSOR forSelect PtnLimitTime from tblPlanTableNameopen cursor1fetch next from cursor1 into @PtnLimitTimewhile(@@fetch_status=0)beginprint @PtnLimitTimefetch next from cursor1 into @PtnLimitTimeendclose cursor1deallocate cursor1
随时随地看视频慕课网APP

相关分类

SQL Server
我要回答