DECLARE AssigChart CURSOR FOR SELECT vad_id_no, drv_id_no, vad_st_dt, vad_st_tm, vad_fn_dt, vad_fn_tm FROM lu02vad WHERE lTachoSmartCardID = @tachoSmartCardID
OPEN AssigChart FETCH NEXT FROM AssigChart INTO @ChartID, @drvid, @dStartTime, @lStartTime, @dEndTime, @lEndTime
WHILE (@@FETCH_STATUS <> -1)
BEGIN
<------------------some processing ---------------------->>>>>>>>
FETCH NEXT FROM AssigChart
INTO @ChartID, @drvid, @dStartTime, @lStartTime, @dEndTime, @lEndTime
END
CLOSE AssigChart
DEALLOCATE AssigChart
答案 0 :(得分:1)
@@ FETCH_Status返回以下值....
0 The FETCH statement was successful.
-1 The FETCH statement failed or the row was beyond the result set.
-2 The row fetched is missing.
因此,如果不成功,它可以返回-1和-2任何人,要么你可以像这样检查....
while @@FETCH_STATUS=0
或
while @@FETCH_STATUS<>-1 and @@FETCH_STATUS<>-2
答案 1 :(得分:1)
试试这个 -
DECLARE AssigChart CURSOR READ_ONLY LOCAL FAST_FORWARD FOR
SELECT vad_id_no, drv_id_no, vad_st_dt, vad_st_tm, vad_fn_dt, vad_fn_tm
FROM lu02vad
WHERE lTachoSmartCardID = @tachoSmartCardID
OPEN AssigChart
FETCH NEXT FROM AssigChart INTO
@ChartID
, @drvid
, @dStartTime
, @lStartTime
, @dEndTime
, @lEndTime
WHILE @@FETCH_STATUS = 0 BEGIN
-- your statements
FETCH NEXT FROM AssigChart INTO
@ChartID
, @drvid
, @dStartTime
, @lStartTime
, @dEndTime
, @lEndTime
END
CLOSE AssigChart
DEALLOCATE AssigChart