现在的位置: 首页 > 综合 > 正文

在存储过程中循环表中的记录集

2012年04月11日 ⁄ 综合 ⁄ 共 356字 ⁄ 字号 评论关闭
代码
    DECLARE @tempFriend varchar(5000)
    
DECLARE rs CURSOR  LOCAL SCROLL FOR
    
select Friend  from Friend where Username = @Username
    
OPEN rs 
    
FETCH NEXT FROM rs INTO @tempFriend  --循环
     WHILE @@FETCH_STATUS = 0
     
BEGIN
        
SET @Friend = @Friend + @tempFriend
     
FETCH NEXT FROM rs INTO @tempFriend
     
END
     
CLOSE  rs
     
deallocate   rs

抱歉!评论已关闭.