sql server 中游标的使用……
2011-12-14 21:49
288 查看
Create Table Borrowbook( --创建表学生借书
Borrowbook int identity(1,1),
StutID int ,
StuFeeID int ,
BorrowDate datetime,
ReturnDAte Datetime,
Fee Money
)
Create Table StuFee( --学生费用结算表
StuFeeID int primarykey ,
StuID int ,
BorrowBookAllFee Money,
)
--声明一个游标
Declare curStuFee Cursor
for
Select StuFeeID From StudentFee
--声明两个费用变量
Declare @mBorrowBookAllFee Money --总费用
Declare @iStuFeeID Int --借书结算号
--初始化
Set @mBorrowBookAllFee=0
Set @iStuFeeID=0
--打开游标
Open curStuFee
--循环并提取记录
Fetch Next From curStudentFee Into @iStudentFeeID
While ( @@Fetch_Status=0 )
begin
--从借书记录中计算某一学生的借书总记录的总费用
Select @mBorrowBookAllFee=Sum(Fee)
From Borrowbook
Where StuFeeID=@iStuFeeID
--更新到汇总表。
Update StuFee Set BorrowBookAllFee=@mBorrowBookAllFee
Where StuFeeID=@iStudnetFeeID
Fetch Next From curStuFee Into @mFee
end
--关闭游标
Close curStuFee
--释放游标
Deallocate curStuFee
Borrowbook int identity(1,1),
StutID int ,
StuFeeID int ,
BorrowDate datetime,
ReturnDAte Datetime,
Fee Money
)
Create Table StuFee( --学生费用结算表
StuFeeID int primarykey ,
StuID int ,
BorrowBookAllFee Money,
)
--声明一个游标
Declare curStuFee Cursor
for
Select StuFeeID From StudentFee
--声明两个费用变量
Declare @mBorrowBookAllFee Money --总费用
Declare @iStuFeeID Int --借书结算号
--初始化
Set @mBorrowBookAllFee=0
Set @iStuFeeID=0
--打开游标
Open curStuFee
--循环并提取记录
Fetch Next From curStudentFee Into @iStudentFeeID
While ( @@Fetch_Status=0 )
begin
--从借书记录中计算某一学生的借书总记录的总费用
Select @mBorrowBookAllFee=Sum(Fee)
From Borrowbook
Where StuFeeID=@iStuFeeID
--更新到汇总表。
Update StuFee Set BorrowBookAllFee=@mBorrowBookAllFee
Where StuFeeID=@iStudnetFeeID
Fetch Next From curStuFee Into @mFee
end
--关闭游标
Close curStuFee
--释放游标
Deallocate curStuFee
相关文章推荐
- SQL Server 2008 游标使用实例
- SQL Server游标的使用【转】
- SQL Server游标的使用【转】
- SQL Server游标的使用【转】
- SQL Server 2000游标使用方法
- sql server游标的使用
- SQL Server 2000中如何使用游标
- sql server 2000更新技巧&select 查询中带参数,游标中使用exec
- SQL Server游标的使用【转】
- 如何使用SQL Server游标
- SQL Server 2008 游标使用实例
- SQL Server游标的使用【转】
- SQL Server 游标基础使用
- SQL server 游标,随机数使用
- count distinct 组合,UPDATE TOP 组合,Sql server 游标使用
- SQL SERVER 游标使用
- SQL Server游标的使用【转】
- sql server 2000/2005 游标的使用操作
- TSQL(SQL Server)使用语句双游标循环多表操作
- SQL Server游标的使用【转】