求救!!!有关存储过程....

土星人在海边 2003-04-09 03:54:04
在存储过程中如何实现一下功能:
1。查询表A中符合条件的结果n条
2。对每一条记录进行操作
需要实现例如 i:=1 to n do
begin
......
query.next;//这个怎么实现??
end;
谢谢 谢谢
...全文
28 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
thanks
回复
newdongkui 2003-04-09
你非要这样的话有游标吧
USE pubs
GO

-- Declare the variables to store the values returned by FETCH.
DECLARE @au_lname varchar(40), @au_fname varchar(20)


DECLARE authors_cursor CURSOR FOR
SELECT au_lname, au_fname FROM authors
WHERE au_lname LIKE "B%"
ORDER BY au_lname, au_fname

OPEN authors_cursor

-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.

FETCH NEXT FROM authors_cursor
INTO @au_lname, @au_fname

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN

-- Concatenate and display the current values in the variables.
PRINT "Author: " + @au_fname + " " + @au_lname

-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM authors_cursor
INTO @au_lname, @au_fname
END

CLOSE authors_cursor
DEALLOCATE authors_cursor
GO

回复
pengdali 2003-04-09
use pubs----------选择
go

declare dali_cursor scroll cursor for------------定义游标
select * from jobs where max_lvl>100 ----------游标体查找语句
open dali_cursor-----------------打开游标



-------fetch next from dali_cursor------------提取游标-----next---last




close dali_cursor------------------关闭游标
deallocate dali_cursor------------释放游标
回复
pengdali 2003-04-09
declare cursor_insert cursor for select c# from cs
declare
@i int
open cursor_insert
fetch cursor_insert into @i
while @@fetch_status=0
begin
print @i
fetch cursor_insert into @i
end
close cursor_insert
deallocate cursor_insert
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2003-04-09 03:54
社区公告
暂无公告