alter table M add 余额 intdeclare @rem int
declare @aid int
declare @borrow int
declare @lend int
declare mycursor cursor for
select aid, 贷发生,借发生 from M
select @rem=0
open mycursorfetch mycursor into
@aid, @lend,@borrow
while(@@fetch_status=0)
begin select @rem=@rem+@lend-@borrow
update M set 余额=@rem where aid=@aid
fetch next from mycursor into @aid, @lend,@borrow
end
close mycursor
deallocate mycursor
declare @aid int
declare @borrow int
declare @lend int
declare mycursor cursor for
select aid, 贷发生,借发生 from M
select @rem=0
open mycursorfetch mycursor into
@aid, @lend,@borrow
while(@@fetch_status=0)
begin select @rem=@rem+@lend-@borrow
update M set 余额=@rem where aid=@aid
fetch next from mycursor into @aid, @lend,@borrow
end
close mycursor
deallocate mycursor
解决方案 »
- sql for xml 添加根节点属性?
- 视图
- 求一触发器。
- 在view 中可以用cursor嗎,sql server中的哪些語句不能在視圖中使用?
- 高手进,一个服务器的问题。。。。
- PROCEDURE 的怪问题
- SQL Server 的 Microsoft OLE DB 提供者 (0x80040E14) 關鍵字 'between' 附近的語法不正確。
- [急!急!急!]SQL按行遍历
- sqlserver能不能定义数组?他有没有类似VB里的 string类型数据的split方法?有该怎么用?
- 一个很菜的问题,希望大家热忱帮忙,一定给分。
- 求一条select...语句!! 请大家帮帮忘忙!~~~~在线等..........
- 请教一个sql语句的写法,谢谢
insert M select 1,200,100
union all select 2,400,200
union all select 3,200,0
union all select 4,0,100alter table M add 余额 int
declare @rem int
declare @aid int
declare @borrow int
declare @lend int
declare mycursor cursor for
select aid, 贷发生,借发生 from M
select @rem=0
open mycursorfetch mycursor into
@aid, @lend,@borrow
while(@@fetch_status=0)
begin select @rem=@rem+@lend-@borrow
update M set 余额=@rem where aid=@aid
fetch next from mycursor into @aid, @lend,@borrow
end
close mycursor
deallocate mycursor--result
1 200 100 100
2 400 100 300
3 200 0 500
4 0 100 400
from table a
zjmym(缘木)的做法