sql语句游标的写法

时间:2021-09-28 09:48:27

当循环查找一张表的信息时,我们得写一张游标来对每条信息进行操作,具体格式如下

DECLARE @fitemid int

DECLARE #point_cursor CURSOR
FOR
SELECT fitemid
FROM ICStockBillEntry where finterid=1314     --每条信息从头到尾的写入
OPEN #point_cursor
FETCH NEXT FROM #point_cursor INTO @fitemid
while @@fetch_status = 0
BEGIN
select @fitemid= from table          --具体的逻辑
FETCH NEXT FROM #point_cursor INTO @fitemid
END
CLOSE #point_cursor
DEALLOCATE #point_cursor