SQL常用的游标格式
时间:2010-12-16 来源:Aaron.Wu
DECLARE @Name nvarchar(50)
然后定义一个游标(Charges) 并给他指定数据源 (SELECT [Name] FROM ProjList WHERE project = @project)
DECLARE Charges CURSOR FOR
SELECT [Name] FROM ProjList WHERE project = @project
接着打开游标,并取出数据赋值给变量@Name.
OPEN Charges
FETCH NEXT FROM Charges INTO @Name
直到没有数据可读的时候停止.
WHILE @@fetch_status = 0
BEGIN
--do something ...
--继续读取下一条数据
FETCH NEXT FROM Charges INTO @Name
END
关闭游标
CLOSE Charges
释放游标
DEALLOCATE Charges
相关阅读 更多 +