sqlserver 存储过程中循环遍历结果集
sql1=select *from(select *,row_number()over(orderby username)as r...
sql1=select * from (select *, row_number() over(order by username ) as rowNumber from users where regfrom='&admin&') as t where t.rowNumber > 0 and t.rowNumber <= 0 + 30 order by username sql1查询得到一个结果集, 有27条记录。然后sql2=select username,daili from users where username='" + username+ "' or regfrom like '%" + "&" + username+ "&" + "%' order by usernamesql2的username是结果集1里得到的 接着sql3=select username,back_money,back_money2,follows,type from "+ dbleft + "bank_back where username='" + username1+ "' " + ptype + " " + btype + " " + addtime1 + " "+ addtime2 + " order by addtime descsql3的username1和其他参数都是从sql2里得到的 从程序里反映出来的就是for(sql1的结果集){ for(sql2的结果集) { for(sql3的结果集) { 处理...... } }}请问存储过程该怎么实现.记得是用fetch loop 来进行循环遍历,然后可以自定义 type ~~~~(>_<)~~~~ 都忘光光了
展开
1个回答
展开全部
sql1=select * from (select *, row_number() over(order by username ) as rowNumber from users where regfrom='&admin&') as t where t.rowNumber > 0 and t.rowNumber <= 0 + 30 order by username
怎么会有27 条记录呢,除非你的表 一共就27条记录吧。
用游标或临时表
--游标
declare youbiao1 for 查询1
open youbiao1
fetch next from youbiao1 into 变量
while @@FETCH_STATUS = 0
begin
里面一次套用
end
--临时表
declare @ID int
set @ID = 1
while Exists(select * from 表)
begin
--处理
--
set @ID = @ID + 1
end
怎么会有27 条记录呢,除非你的表 一共就27条记录吧。
用游标或临时表
--游标
declare youbiao1 for 查询1
open youbiao1
fetch next from youbiao1 into 变量
while @@FETCH_STATUS = 0
begin
里面一次套用
end
--临时表
declare @ID int
set @ID = 1
while Exists(select * from 表)
begin
--处理
--
set @ID = @ID + 1
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |