首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么在游标中使用存储过程

2012-08-02 
如何在游标中使用存储过程如何在游标中使用存储过程?我建立了一个游标BankStatment求银行的存款declare@re

如何在游标中使用存储过程

如何在游标中使用存储过程?
 
我建立了一个游标BankStatment求银行的存款
 
declare
 @results table
 (
 id int,
 PersonName varchar(100),
 Balance money,
 )
 
declare BankStatment cursor
 for
 select ID from Person
 open BankStatement
 declare @id int
 fetch next from BankStatement into @id
 while 
(@@fetch_status =0)
 begin
 exec GetPersonBalance @id
 insert @results
 fetch next from BankStatement into @id
 end
 deallocate BankStatement
 
这个游标通过表Person中的ID,用存储过程GetPersonBalance计算出PersonName和他的Balance
 
请大家看看我的写的这个哪里错了?
 
为何说Incorrect syntax near the keyword 'fetch'

[解决办法]

SQL code
fetch next into @id from BankStatement --还有需close BankStatementdeallocate BankStatement
[解决办法]
SQL code
--不好意思,你是这里错了,fetch语法没错--insert @results fetch next from BankStatement into @id
[解决办法]
探讨

引用:

SQL code

--不好意思,你是这里错了,fetch语法没错
--insert @results
fetch next from BankStatement into @id


是insert语法有问题吗

[解决办法]
SQL code
 insert @results exec GetPersonBalance @id
[解决办法]
用insert @result values(@id,@PersonName,@Balance)

热点排行
Bad Request.