您的位置:首页 > 数据库

sql 遍历结果集

2015-11-04 10:51 176 查看
declare @temp table
(
[id] int IDENTITY(1,1),
[Name] varchar(10)
)
--select * from @temp
declare @tempId int,@tempName varchar(10)

insert into @temp values('a')
insert into @temp values('b')
insert into @temp values('c')
insert into @temp values('d')
insert into @temp values('e')

--select * from @temp

WHILE EXISTS(select [id] from @temp)
begin
SET ROWCOUNT 1
select @tempId = [id],@tempName=[Name] from @temp
SET ROWCOUNT 0
delete from @temp where [id] = @tempId

print 'Name:----'+@tempName
end


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: